
kernel.elf:     file format elf64-littleriscv


Disassembly of section .text:

0000000080000000 <_entry>:
.section .text
.global _entry
_entry:
    # 设置栈指针
    la sp, stack_top
    80000000:	0001a117          	auipc	sp,0x1a
    80000004:	01010113          	add	sp,sp,16 # 8001a010 <stack_top>
    
       
   
    # 清零BSS段
    la a0, __bss_start
    80000008:	00006517          	auipc	a0,0x6
    8000000c:	69850513          	add	a0,a0,1688 # 800066a0 <kernel_pagetable>
    la a1, __bss_end
    80000010:	00017597          	auipc	a1,0x17
    80000014:	66858593          	add	a1,a1,1640 # 80017678 <__bss_end>
    jal zero_bss
    80000018:	00a000ef          	jal	80000022 <zero_bss>

    

    # 跳转到C主函数
    call start
    8000001c:	1e5000ef          	jal	80000a00 <start>

0000000080000020 <spin>:

spin:
    j spin
    80000020:	a001                	j	80000020 <spin>

0000000080000022 <zero_bss>:

# BSS段清零函数
zero_bss:
    beq a0, a1, zero_done
    80000022:	00b50663          	beq	a0,a1,8000002e <zero_done>
    sw zero, 0(a0)
    80000026:	00052023          	sw	zero,0(a0)
    addi a0, a0, 4
    8000002a:	0511                	add	a0,a0,4
    j zero_bss
    8000002c:	bfdd                	j	80000022 <zero_bss>

000000008000002e <zero_done>:
zero_done:
    8000002e:	8082                	ret

0000000080000030 <main>:
#include "../mm/pmm.h"
#include "../trap/trap.h"
#include "console.h"
#include "../proc/proc.h"

void main(void) {
    80000030:	1141                	add	sp,sp,-16
    80000032:	e406                	sd	ra,8(sp)
  console_init();
    80000034:	0c0000ef          	jal	800000f4 <console_init>
  printf("xv6-riscv: booting...\n");
    80000038:	00005517          	auipc	a0,0x5
    8000003c:	5e850513          	add	a0,a0,1512 # 80005620 <kalloc+0x62>
    80000040:	346000ef          	jal	80000386 <printf>
  
  // 初始化陷阱系统
  trap_init();
    80000044:	1fc010ef          	jal	80001240 <trap_init>
  
  // 初始化物理内存管理
  pmm_init();
    80000048:	249000ef          	jal	80000a90 <pmm_init>
  
  // 初始化内核虚拟内存
  kvminit();
    8000004c:	5b3000ef          	jal	80000dfe <kvminit>
  kvminithart();
    80000050:	66b000ef          	jal	80000eba <kvminithart>
  
  // 初始化进程系统
  procinit();
    80000054:	1be020ef          	jal	80002212 <procinit>
  
  userinit();
    80000058:	454020ef          	jal	800024ac <userinit>

  //test_userProcess();
  // 进入调度器循环（永不返回）
  scheduler();
    8000005c:	60a2                	ld	ra,8(sp)
    8000005e:	0141                	add	sp,sp,16
  scheduler();
    80000060:	7a20206f          	j	80002802 <scheduler>

0000000080000064 <uart_init>:
#define UART_RHR    (UART0 + 0x00)   // receive holding
#define UART_LSR    (UART0 + 0x05)   // line status
#define LSR_TX_IDLE (1 << 5) //THRE，1表示可以发送下一个字符，0表示发送缓冲区满
#define LSR_RX_READY (1 << 0) // Data ready

void uart_init(){}
    80000064:	1141                	add	sp,sp,-16
    80000066:	e422                	sd	s0,8(sp)
    80000068:	0800                	add	s0,sp,16
    8000006a:	6422                	ld	s0,8(sp)
    8000006c:	0141                	add	sp,sp,16
    8000006e:	8082                	ret

0000000080000070 <uart_putc>:

void uart_putc(char c) {
    80000070:	1141                	add	sp,sp,-16
    80000072:	e422                	sd	s0,8(sp)
    80000074:	0800                	add	s0,sp,16
  while ((REG8(UART_LSR) & LSR_TX_IDLE) == 0) { }
    80000076:	10000737          	lui	a4,0x10000
    8000007a:	00574783          	lbu	a5,5(a4) # 10000005 <_entry-0x6ffffffb>
    8000007e:	0207f793          	and	a5,a5,32
    80000082:	dfe5                	beqz	a5,8000007a <uart_putc+0xa>
  REG8(UART_THR) = (uint8)c;
    80000084:	100007b7          	lui	a5,0x10000
    80000088:	00a78023          	sb	a0,0(a5) # 10000000 <_entry-0x70000000>
}
    8000008c:	6422                	ld	s0,8(sp)
    8000008e:	0141                	add	sp,sp,16
    80000090:	8082                	ret

0000000080000092 <uart_puts>:

void uart_puts(const char *s) {
  while (*s) {
    80000092:	00054783          	lbu	a5,0(a0)
    80000096:	cf95                	beqz	a5,800000d2 <uart_puts+0x40>
void uart_puts(const char *s) {
    80000098:	1101                	add	sp,sp,-32
    8000009a:	ec06                	sd	ra,24(sp)
    8000009c:	e822                	sd	s0,16(sp)
    8000009e:	e426                	sd	s1,8(sp)
    800000a0:	e04a                	sd	s2,0(sp)
    800000a2:	1000                	add	s0,sp,32
    800000a4:	84aa                	mv	s1,a0
    if (*s == '\n') uart_putc('\r');
    800000a6:	4929                	li	s2,10
    800000a8:	a809                	j	800000ba <uart_puts+0x28>
    uart_putc(*s++);
    800000aa:	0485                	add	s1,s1,1
    800000ac:	fff4c503          	lbu	a0,-1(s1)
    800000b0:	fc1ff0ef          	jal	80000070 <uart_putc>
  while (*s) {
    800000b4:	0004c783          	lbu	a5,0(s1)
    800000b8:	c799                	beqz	a5,800000c6 <uart_puts+0x34>
    if (*s == '\n') uart_putc('\r');
    800000ba:	ff2798e3          	bne	a5,s2,800000aa <uart_puts+0x18>
    800000be:	4535                	li	a0,13
    800000c0:	fb1ff0ef          	jal	80000070 <uart_putc>
    800000c4:	b7dd                	j	800000aa <uart_puts+0x18>
  }
}
    800000c6:	60e2                	ld	ra,24(sp)
    800000c8:	6442                	ld	s0,16(sp)
    800000ca:	64a2                	ld	s1,8(sp)
    800000cc:	6902                	ld	s2,0(sp)
    800000ce:	6105                	add	sp,sp,32
    800000d0:	8082                	ret
    800000d2:	8082                	ret

00000000800000d4 <uart_getc>:

int uart_getc(void) {
    800000d4:	1141                	add	sp,sp,-16
    800000d6:	e422                	sd	s0,8(sp)
    800000d8:	0800                	add	s0,sp,16
  while ((REG8(UART_LSR) & LSR_RX_READY) == 0) {
    800000da:	10000737          	lui	a4,0x10000
    800000de:	00574783          	lbu	a5,5(a4) # 10000005 <_entry-0x6ffffffb>
    800000e2:	8b85                	and	a5,a5,1
    800000e4:	dfed                	beqz	a5,800000de <uart_getc+0xa>
    // busy wait for data
  }
  return REG8(UART_RHR);
    800000e6:	100007b7          	lui	a5,0x10000
    800000ea:	0007c503          	lbu	a0,0(a5) # 10000000 <_entry-0x70000000>
    800000ee:	6422                	ld	s0,8(sp)
    800000f0:	0141                	add	sp,sp,16
    800000f2:	8082                	ret

00000000800000f4 <console_init>:
#include "console.h"
#include "uart.h"
#include "printf.h"
// 控制台初始化
void console_init(void) {
    800000f4:	1141                	add	sp,sp,-16
    800000f6:	e406                	sd	ra,8(sp)
    800000f8:	e022                	sd	s0,0(sp)
    800000fa:	0800                	add	s0,sp,16
    uart_init();
    800000fc:	f69ff0ef          	jal	80000064 <uart_init>
}
    80000100:	60a2                	ld	ra,8(sp)
    80000102:	6402                	ld	s0,0(sp)
    80000104:	0141                	add	sp,sp,16
    80000106:	8082                	ret

0000000080000108 <consputc>:

// 输出字符到控制台（带特殊字符处理）
void consputc(int c) {
    80000108:	1141                	add	sp,sp,-16
    8000010a:	e406                	sd	ra,8(sp)
    8000010c:	e022                	sd	s0,0(sp)
    8000010e:	0800                	add	s0,sp,16
    if(c == BACKSPACE){
    80000110:	10000793          	li	a5,256
    80000114:	00f50a63          	beq	a0,a5,80000128 <consputc+0x20>
        // 退格处理：回退、空格、再回退
        uart_putc('\b');
        uart_putc(' ');
        uart_putc('\b');
    } else {
        uart_putc(c);
    80000118:	0ff57513          	zext.b	a0,a0
    8000011c:	f55ff0ef          	jal	80000070 <uart_putc>
    }
}
    80000120:	60a2                	ld	ra,8(sp)
    80000122:	6402                	ld	s0,0(sp)
    80000124:	0141                	add	sp,sp,16
    80000126:	8082                	ret
        uart_putc('\b');
    80000128:	4521                	li	a0,8
    8000012a:	f47ff0ef          	jal	80000070 <uart_putc>
        uart_putc(' ');
    8000012e:	02000513          	li	a0,32
    80000132:	f3fff0ef          	jal	80000070 <uart_putc>
        uart_putc('\b');
    80000136:	4521                	li	a0,8
    80000138:	f39ff0ef          	jal	80000070 <uart_putc>
    8000013c:	b7d5                	j	80000120 <consputc+0x18>

000000008000013e <console_putc>:

// 简单的字符输出
void console_putc(char c) {
    8000013e:	1141                	add	sp,sp,-16
    80000140:	e406                	sd	ra,8(sp)
    80000142:	e022                	sd	s0,0(sp)
    80000144:	0800                	add	s0,sp,16
    consputc(c);
    80000146:	fc3ff0ef          	jal	80000108 <consputc>
}
    8000014a:	60a2                	ld	ra,8(sp)
    8000014c:	6402                	ld	s0,0(sp)
    8000014e:	0141                	add	sp,sp,16
    80000150:	8082                	ret

0000000080000152 <console_puts>:

// 字符串输出
void console_puts(const char *s) {
    while (*s) {
    80000152:	00054783          	lbu	a5,0(a0)
    80000156:	cf95                	beqz	a5,80000192 <console_puts+0x40>
void console_puts(const char *s) {
    80000158:	1101                	add	sp,sp,-32
    8000015a:	ec06                	sd	ra,24(sp)
    8000015c:	e822                	sd	s0,16(sp)
    8000015e:	e426                	sd	s1,8(sp)
    80000160:	e04a                	sd	s2,0(sp)
    80000162:	1000                	add	s0,sp,32
    80000164:	84aa                	mv	s1,a0
        if (*s == '\n') console_putc('\r');
    80000166:	4929                	li	s2,10
    80000168:	a809                	j	8000017a <console_puts+0x28>
        console_putc(*s++);
    8000016a:	0485                	add	s1,s1,1
    consputc(c);
    8000016c:	fff4c503          	lbu	a0,-1(s1)
    80000170:	f99ff0ef          	jal	80000108 <consputc>
    while (*s) {
    80000174:	0004c783          	lbu	a5,0(s1)
    80000178:	c799                	beqz	a5,80000186 <console_puts+0x34>
        if (*s == '\n') console_putc('\r');
    8000017a:	ff2798e3          	bne	a5,s2,8000016a <console_puts+0x18>
    consputc(c);
    8000017e:	4535                	li	a0,13
    80000180:	f89ff0ef          	jal	80000108 <consputc>
}
    80000184:	b7dd                	j	8000016a <console_puts+0x18>
    }
}
    80000186:	60e2                	ld	ra,24(sp)
    80000188:	6442                	ld	s0,16(sp)
    8000018a:	64a2                	ld	s1,8(sp)
    8000018c:	6902                	ld	s2,0(sp)
    8000018e:	6105                	add	sp,sp,32
    80000190:	8082                	ret
    80000192:	8082                	ret

0000000080000194 <clear_screen>:

// 清屏功能
void clear_screen(void) {
    80000194:	1141                	add	sp,sp,-16
    80000196:	e406                	sd	ra,8(sp)
    80000198:	e022                	sd	s0,0(sp)
    8000019a:	0800                	add	s0,sp,16
    // 使用ANSI转义序列清屏
    console_puts("\033[2J");  // 清除整个屏幕
    8000019c:	00005517          	auipc	a0,0x5
    800001a0:	49c50513          	add	a0,a0,1180 # 80005638 <kalloc+0x7a>
    800001a4:	fafff0ef          	jal	80000152 <console_puts>
    console_puts("\033[H");   // 光标回到左上角
    800001a8:	00005517          	auipc	a0,0x5
    800001ac:	49850513          	add	a0,a0,1176 # 80005640 <kalloc+0x82>
    800001b0:	fa3ff0ef          	jal	80000152 <console_puts>
}
    800001b4:	60a2                	ld	ra,8(sp)
    800001b6:	6402                	ld	s0,0(sp)
    800001b8:	0141                	add	sp,sp,16
    800001ba:	8082                	ret

00000000800001bc <clear_line>:


// 清除当前行
void clear_line(void) {
    800001bc:	1141                	add	sp,sp,-16
    800001be:	e406                	sd	ra,8(sp)
    800001c0:	e022                	sd	s0,0(sp)
    800001c2:	0800                	add	s0,sp,16
    console_puts("\033[K");  // 清除整行
    800001c4:	00005517          	auipc	a0,0x5
    800001c8:	48450513          	add	a0,a0,1156 # 80005648 <kalloc+0x8a>
    800001cc:	f87ff0ef          	jal	80000152 <console_puts>
    console_puts("\r");       // 回到行首
    800001d0:	00005517          	auipc	a0,0x5
    800001d4:	48050513          	add	a0,a0,1152 # 80005650 <kalloc+0x92>
    800001d8:	f7bff0ef          	jal	80000152 <console_puts>
}
    800001dc:	60a2                	ld	ra,8(sp)
    800001de:	6402                	ld	s0,0(sp)
    800001e0:	0141                	add	sp,sp,16
    800001e2:	8082                	ret

00000000800001e4 <console_set_color>:

// 设置文本颜色
void console_set_color(int color) {
    800001e4:	1101                	add	sp,sp,-32
    800001e6:	ec06                	sd	ra,24(sp)
    800001e8:	e822                	sd	s0,16(sp)
    800001ea:	1000                	add	s0,sp,32
    800001ec:	862a                	mv	a2,a0
    char buf[8];
    sprintf(buf, "\033[%dm", color);
    800001ee:	00005597          	auipc	a1,0x5
    800001f2:	46a58593          	add	a1,a1,1130 # 80005658 <kalloc+0x9a>
    800001f6:	fe840513          	add	a0,s0,-24
    800001fa:	3d0000ef          	jal	800005ca <sprintf>
    console_puts(buf);
    800001fe:	fe840513          	add	a0,s0,-24
    80000202:	f51ff0ef          	jal	80000152 <console_puts>
}
    80000206:	60e2                	ld	ra,24(sp)
    80000208:	6442                	ld	s0,16(sp)
    8000020a:	6105                	add	sp,sp,32
    8000020c:	8082                	ret

000000008000020e <console_reset_color>:

// 重置颜色到默认
void console_reset_color(void) {
    8000020e:	1141                	add	sp,sp,-16
    80000210:	e406                	sd	ra,8(sp)
    80000212:	e022                	sd	s0,0(sp)
    80000214:	0800                	add	s0,sp,16
    console_puts("\033[0m");  // 重置所有属性
    80000216:	00005517          	auipc	a0,0x5
    8000021a:	44a50513          	add	a0,a0,1098 # 80005660 <kalloc+0xa2>
    8000021e:	f35ff0ef          	jal	80000152 <console_puts>
}
    80000222:	60a2                	ld	ra,8(sp)
    80000224:	6402                	ld	s0,0(sp)
    80000226:	0141                	add	sp,sp,16
    80000228:	8082                	ret

000000008000022a <console_set_color_bg>:

// 设置颜色和背景
void console_set_color_bg(int fg_color, int bg_color) {
    8000022a:	1101                	add	sp,sp,-32
    8000022c:	ec06                	sd	ra,24(sp)
    8000022e:	e822                	sd	s0,16(sp)
    80000230:	1000                	add	s0,sp,32
    80000232:	862a                	mv	a2,a0
    80000234:	86ae                	mv	a3,a1
    char buf[16];
    sprintf(buf, "\033[%d;%dm", fg_color, bg_color);
    80000236:	00005597          	auipc	a1,0x5
    8000023a:	43258593          	add	a1,a1,1074 # 80005668 <kalloc+0xaa>
    8000023e:	fe040513          	add	a0,s0,-32
    80000242:	388000ef          	jal	800005ca <sprintf>
    console_puts(buf);
    80000246:	fe040513          	add	a0,s0,-32
    8000024a:	f09ff0ef          	jal	80000152 <console_puts>
}
    8000024e:	60e2                	ld	ra,24(sp)
    80000250:	6442                	ld	s0,16(sp)
    80000252:	6105                	add	sp,sp,32
    80000254:	8082                	ret

0000000080000256 <number_to_buffer>:
    va_end(ap);
    return 0;
}

// 数字转换为字符串到缓冲区（sprintf专用）
static int number_to_buffer(int num, int base, int sign, char *buf) {
    80000256:	7139                	add	sp,sp,-64
    80000258:	fc22                	sd	s0,56(sp)
    8000025a:	0080                	add	s0,sp,64
    char digits[] = "0123456789ABCDEF";
    8000025c:	00005797          	auipc	a5,0x5
    80000260:	41c78793          	add	a5,a5,1052 # 80005678 <kalloc+0xba>
    80000264:	6398                	ld	a4,0(a5)
    80000266:	fce43c23          	sd	a4,-40(s0)
    8000026a:	6798                	ld	a4,8(a5)
    8000026c:	fee43023          	sd	a4,-32(s0)
    80000270:	0107c783          	lbu	a5,16(a5)
    80000274:	fef40423          	sb	a5,-24(s0)
    int count = 0;
    char temp_buf[16];
    char *ptr = temp_buf;
    
    // 处理符号
    if (sign && num < 0) {
    80000278:	c219                	beqz	a2,8000027e <number_to_buffer+0x28>
    8000027a:	06054763          	bltz	a0,800002e8 <number_to_buffer+0x92>
        negative = 1;
        n = -num;
    } else {
        n = num;
    8000027e:	0005071b          	sext.w	a4,a0
    int negative = 0;
    80000282:	4801                	li	a6,0
    80000284:	fc840513          	add	a0,s0,-56
    }
    
    // 转换为字符串（逆序）
    do {
        *ptr++ = digits[n % base];
    80000288:	2581                	sext.w	a1,a1
    8000028a:	862a                	mv	a2,a0
    8000028c:	0505                	add	a0,a0,1
    8000028e:	02b777bb          	remuw	a5,a4,a1
    80000292:	1782                	sll	a5,a5,0x20
    80000294:	9381                	srl	a5,a5,0x20
    80000296:	17c1                	add	a5,a5,-16
    80000298:	97a2                	add	a5,a5,s0
    8000029a:	fe87c783          	lbu	a5,-24(a5)
    8000029e:	fef50fa3          	sb	a5,-1(a0)
        n /= base;
    800002a2:	0007079b          	sext.w	a5,a4
    800002a6:	02b7573b          	divuw	a4,a4,a1
    } while (n > 0);
    800002aa:	feb7f0e3          	bgeu	a5,a1,8000028a <number_to_buffer+0x34>
    
    // 添加负号
    if (negative) {
    800002ae:	00080863          	beqz	a6,800002be <number_to_buffer+0x68>
        *ptr++ = '-';
    800002b2:	02d00793          	li	a5,45
    800002b6:	00f50023          	sb	a5,0(a0)
    800002ba:	00260513          	add	a0,a2,2
    }
    
    // 逆序复制到目标缓冲区
    while (ptr > temp_buf) {
    800002be:	fc840793          	add	a5,s0,-56
    800002c2:	02a7f763          	bgeu	a5,a0,800002f0 <number_to_buffer+0x9a>
    800002c6:	87aa                	mv	a5,a0
    800002c8:	fc840613          	add	a2,s0,-56
        *buf++ = *--ptr;
    800002cc:	17fd                	add	a5,a5,-1
    800002ce:	0685                	add	a3,a3,1
    800002d0:	0007c703          	lbu	a4,0(a5)
    800002d4:	fee68fa3          	sb	a4,-1(a3)
    while (ptr > temp_buf) {
    800002d8:	fec79ae3          	bne	a5,a2,800002cc <number_to_buffer+0x76>
        count++;
    800002dc:	fc840793          	add	a5,s0,-56
    800002e0:	9d1d                	subw	a0,a0,a5
    }
    
    return count;
}
    800002e2:	7462                	ld	s0,56(sp)
    800002e4:	6121                	add	sp,sp,64
    800002e6:	8082                	ret
        n = -num;
    800002e8:	40a0073b          	negw	a4,a0
        negative = 1;
    800002ec:	4805                	li	a6,1
        n = -num;
    800002ee:	bf59                	j	80000284 <number_to_buffer+0x2e>
    while (ptr > temp_buf) {
    800002f0:	4501                	li	a0,0
    800002f2:	bfc5                	j	800002e2 <number_to_buffer+0x8c>

00000000800002f4 <print_number>:
static void print_number(int num, int base, int sign) {
    800002f4:	7179                	add	sp,sp,-48
    800002f6:	f406                	sd	ra,40(sp)
    800002f8:	f022                	sd	s0,32(sp)
    800002fa:	ec26                	sd	s1,24(sp)
    800002fc:	e84a                	sd	s2,16(sp)
    800002fe:	1800                	add	s0,sp,48
    if(base<=0){
    80000300:	06b05863          	blez	a1,80000370 <print_number+0x7c>
    if (sign && num < 0) {
    80000304:	c219                	beqz	a2,8000030a <print_number+0x16>
    80000306:	06054c63          	bltz	a0,8000037e <print_number+0x8a>
        n = num;
    8000030a:	2501                	sext.w	a0,a0
    int negative = 0;
    8000030c:	4601                	li	a2,0
    8000030e:	fd040493          	add	s1,s0,-48
        *ptr++ = digits[n % base];
    80000312:	2581                	sext.w	a1,a1
    80000314:	00005717          	auipc	a4,0x5
    80000318:	36470713          	add	a4,a4,868 # 80005678 <kalloc+0xba>
    8000031c:	86a6                	mv	a3,s1
    8000031e:	0485                	add	s1,s1,1
    80000320:	02b577bb          	remuw	a5,a0,a1
    80000324:	1782                	sll	a5,a5,0x20
    80000326:	9381                	srl	a5,a5,0x20
    80000328:	97ba                	add	a5,a5,a4
    8000032a:	0007c783          	lbu	a5,0(a5)
    8000032e:	fef48fa3          	sb	a5,-1(s1)
        n /= base;
    80000332:	0005079b          	sext.w	a5,a0
    80000336:	02b5553b          	divuw	a0,a0,a1
    } while (n > 0);
    8000033a:	feb7f1e3          	bgeu	a5,a1,8000031c <print_number+0x28>
    if (negative) {
    8000033e:	c619                	beqz	a2,8000034c <print_number+0x58>
        *ptr++ = '-';
    80000340:	02d00793          	li	a5,45
    80000344:	00f48023          	sb	a5,0(s1)
    80000348:	00268493          	add	s1,a3,2
    while (ptr > buf) {
    8000034c:	fd040793          	add	a5,s0,-48
    80000350:	0097fa63          	bgeu	a5,s1,80000364 <print_number+0x70>
    80000354:	893e                	mv	s2,a5
        console_putc(*--ptr);
    80000356:	14fd                	add	s1,s1,-1
    80000358:	0004c503          	lbu	a0,0(s1)
    8000035c:	de3ff0ef          	jal	8000013e <console_putc>
    while (ptr > buf) {
    80000360:	ff249be3          	bne	s1,s2,80000356 <print_number+0x62>
}
    80000364:	70a2                	ld	ra,40(sp)
    80000366:	7402                	ld	s0,32(sp)
    80000368:	64e2                	ld	s1,24(sp)
    8000036a:	6942                	ld	s2,16(sp)
    8000036c:	6145                	add	sp,sp,48
    8000036e:	8082                	ret
        console_puts("wrong base input!");
    80000370:	00005517          	auipc	a0,0x5
    80000374:	32050513          	add	a0,a0,800 # 80005690 <kalloc+0xd2>
    80000378:	ddbff0ef          	jal	80000152 <console_puts>
        return;
    8000037c:	b7e5                	j	80000364 <print_number+0x70>
        n = -num;
    8000037e:	40a0053b          	negw	a0,a0
        negative = 1;
    80000382:	4605                	li	a2,1
        n = -num;
    80000384:	b769                	j	8000030e <print_number+0x1a>

0000000080000386 <printf>:
int printf(const char *fmt, ...) {
    80000386:	7155                	add	sp,sp,-208
    80000388:	e506                	sd	ra,136(sp)
    8000038a:	e122                	sd	s0,128(sp)
    8000038c:	fca6                	sd	s1,120(sp)
    8000038e:	f8ca                	sd	s2,112(sp)
    80000390:	f4ce                	sd	s3,104(sp)
    80000392:	f0d2                	sd	s4,96(sp)
    80000394:	ecd6                	sd	s5,88(sp)
    80000396:	e8da                	sd	s6,80(sp)
    80000398:	e4de                	sd	s7,72(sp)
    8000039a:	e0e2                	sd	s8,64(sp)
    8000039c:	fc66                	sd	s9,56(sp)
    8000039e:	0900                	add	s0,sp,144
    800003a0:	892a                	mv	s2,a0
    800003a2:	e40c                	sd	a1,8(s0)
    800003a4:	e810                	sd	a2,16(s0)
    800003a6:	ec14                	sd	a3,24(s0)
    800003a8:	f018                	sd	a4,32(s0)
    800003aa:	f41c                	sd	a5,40(s0)
    800003ac:	03043823          	sd	a6,48(s0)
    800003b0:	03143c23          	sd	a7,56(s0)
    va_start(ap, fmt);
    800003b4:	00840793          	add	a5,s0,8
    800003b8:	f8f43c23          	sd	a5,-104(s0)
    for (int i = 0; fmt[i]; i++) {
    800003bc:	00054503          	lbu	a0,0(a0)
    800003c0:	1e050763          	beqz	a0,800005ae <printf+0x228>
    800003c4:	4c81                	li	s9,0
        if (fmt[i] == '%') {
    800003c6:	02500a13          	li	s4,37
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    800003ca:	06c00b13          	li	s6,108
                switch (fmt[i]) {
    800003ce:	4ad5                	li	s5,21
    800003d0:	00005b97          	auipc	s7,0x5
    800003d4:	304b8b93          	add	s7,s7,772 # 800056d4 <kalloc+0x116>
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    800003d8:	07800c13          	li	s8,120
    800003dc:	aa59                	j	80000572 <printf+0x1ec>
    800003de:	0014c783          	lbu	a5,1(s1)
    800003e2:	01878c63          	beq	a5,s8,800003fa <printf+0x74>
                        console_putc('%');
    800003e6:	02500513          	li	a0,37
    800003ea:	d55ff0ef          	jal	8000013e <console_putc>
                        console_putc(fmt[i]);
    800003ee:	0004c503          	lbu	a0,0(s1)
    800003f2:	d4dff0ef          	jal	8000013e <console_putc>
            i++;
    800003f6:	8cce                	mv	s9,s3
                        break;
    800003f8:	a2bd                	j	80000566 <printf+0x1e0>
                i++; // 跳过'l'
    800003fa:	2c89                	addw	s9,s9,2
                print_number64(va_arg(ap, uint64), 16, 0);
    800003fc:	f9843783          	ld	a5,-104(s0)
    80000400:	00878713          	add	a4,a5,8
    80000404:	f8e43c23          	sd	a4,-104(s0)
    80000408:	639c                	ld	a5,0(a5)
    8000040a:	f7840493          	add	s1,s0,-136
        *ptr++ = digits[n % base];
    8000040e:	00005617          	auipc	a2,0x5
    80000412:	29a60613          	add	a2,a2,666 # 800056a8 <kalloc+0xea>
    } while (n > 0);
    80000416:	46bd                	li	a3,15
        *ptr++ = digits[n % base];
    80000418:	0485                	add	s1,s1,1
    8000041a:	00f7f713          	and	a4,a5,15
    8000041e:	9732                	add	a4,a4,a2
    80000420:	00074703          	lbu	a4,0(a4)
    80000424:	fee48fa3          	sb	a4,-1(s1)
        n /= base;
    80000428:	873e                	mv	a4,a5
    8000042a:	8391                	srl	a5,a5,0x4
    } while (n > 0);
    8000042c:	fee6e6e3          	bltu	a3,a4,80000418 <printf+0x92>
    while (ptr > buf) {
    80000430:	f7840793          	add	a5,s0,-136
    80000434:	1297f963          	bgeu	a5,s1,80000566 <printf+0x1e0>
    80000438:	89be                	mv	s3,a5
        console_putc(*--ptr);
    8000043a:	14fd                	add	s1,s1,-1
    8000043c:	0004c503          	lbu	a0,0(s1)
    80000440:	cffff0ef          	jal	8000013e <console_putc>
    while (ptr > buf) {
    80000444:	ff349be3          	bne	s1,s3,8000043a <printf+0xb4>
    80000448:	aa39                	j	80000566 <printf+0x1e0>
                        print_number(va_arg(ap, int), 10, 1);
    8000044a:	f9843783          	ld	a5,-104(s0)
    8000044e:	00878713          	add	a4,a5,8
    80000452:	f8e43c23          	sd	a4,-104(s0)
    80000456:	4605                	li	a2,1
    80000458:	45a9                	li	a1,10
    8000045a:	4388                	lw	a0,0(a5)
    8000045c:	e99ff0ef          	jal	800002f4 <print_number>
            i++;
    80000460:	8cce                	mv	s9,s3
                        break;
    80000462:	a211                	j	80000566 <printf+0x1e0>
                        print_number(va_arg(ap, int), 16, 0);
    80000464:	f9843783          	ld	a5,-104(s0)
    80000468:	00878713          	add	a4,a5,8
    8000046c:	f8e43c23          	sd	a4,-104(s0)
    80000470:	4601                	li	a2,0
    80000472:	45c1                	li	a1,16
    80000474:	4388                	lw	a0,0(a5)
    80000476:	e7fff0ef          	jal	800002f4 <print_number>
            i++;
    8000047a:	8cce                	mv	s9,s3
                        break;
    8000047c:	a0ed                	j	80000566 <printf+0x1e0>
                        print_pointer(va_arg(ap, uint64));
    8000047e:	f9843783          	ld	a5,-104(s0)
    80000482:	00878713          	add	a4,a5,8
    80000486:	f8e43c23          	sd	a4,-104(s0)
    8000048a:	0007bc83          	ld	s9,0(a5)
    console_putc('0');
    8000048e:	03000513          	li	a0,48
    80000492:	cadff0ef          	jal	8000013e <console_putc>
    console_putc('x');
    80000496:	07800513          	li	a0,120
    8000049a:	ca5ff0ef          	jal	8000013e <console_putc>
    char *ptr_buf = buf;
    8000049e:	f7840493          	add	s1,s0,-136
        *ptr_buf++ = digits[n % 16];
    800004a2:	00005697          	auipc	a3,0x5
    800004a6:	20668693          	add	a3,a3,518 # 800056a8 <kalloc+0xea>
    } while (n > 0);
    800004aa:	473d                	li	a4,15
    if (ptr == 0) {
    800004ac:	040c8f63          	beqz	s9,8000050a <printf+0x184>
        *ptr_buf++ = digits[n % 16];
    800004b0:	0485                	add	s1,s1,1
    800004b2:	00fcf793          	and	a5,s9,15
    800004b6:	97b6                	add	a5,a5,a3
    800004b8:	0007c783          	lbu	a5,0(a5)
    800004bc:	fef48fa3          	sb	a5,-1(s1)
        n /= 16;
    800004c0:	87e6                	mv	a5,s9
    800004c2:	004cdc93          	srl	s9,s9,0x4
    } while (n > 0);
    800004c6:	fef765e3          	bltu	a4,a5,800004b0 <printf+0x12a>
    while (ptr_buf - buf < 8) {
    800004ca:	f7840793          	add	a5,s0,-136
    800004ce:	40f487b3          	sub	a5,s1,a5
    800004d2:	471d                	li	a4,7
    800004d4:	00f74d63          	blt	a4,a5,800004ee <printf+0x168>
        *ptr_buf++ = '0';
    800004d8:	03000613          	li	a2,48
    while (ptr_buf - buf < 8) {
    800004dc:	f7840693          	add	a3,s0,-136
        *ptr_buf++ = '0';
    800004e0:	0485                	add	s1,s1,1
    800004e2:	fec48fa3          	sb	a2,-1(s1)
    while (ptr_buf - buf < 8) {
    800004e6:	40d487b3          	sub	a5,s1,a3
    800004ea:	fef75be3          	bge	a4,a5,800004e0 <printf+0x15a>
    while (ptr_buf > buf) {
    800004ee:	f7840793          	add	a5,s0,-136
    800004f2:	0097fa63          	bgeu	a5,s1,80000506 <printf+0x180>
    800004f6:	8cbe                	mv	s9,a5
        console_putc(*--ptr_buf);
    800004f8:	14fd                	add	s1,s1,-1
    800004fa:	0004c503          	lbu	a0,0(s1)
    800004fe:	c41ff0ef          	jal	8000013e <console_putc>
    while (ptr_buf > buf) {
    80000502:	ff949be3          	bne	s1,s9,800004f8 <printf+0x172>
            i++;
    80000506:	8cce                	mv	s9,s3
    80000508:	a8b9                	j	80000566 <printf+0x1e0>
        console_putc('0');
    8000050a:	03000513          	li	a0,48
    8000050e:	c31ff0ef          	jal	8000013e <console_putc>
            i++;
    80000512:	8cce                	mv	s9,s3
    80000514:	a889                	j	80000566 <printf+0x1e0>
                        print_string(va_arg(ap, char*));
    80000516:	f9843783          	ld	a5,-104(s0)
    8000051a:	00878713          	add	a4,a5,8
    8000051e:	f8e43c23          	sd	a4,-104(s0)
    80000522:	6388                	ld	a0,0(a5)
    if (s == 0) {
    80000524:	c509                	beqz	a0,8000052e <printf+0x1a8>
        console_puts(s);
    80000526:	c2dff0ef          	jal	80000152 <console_puts>
            i++;
    8000052a:	8cce                	mv	s9,s3
    8000052c:	a82d                	j	80000566 <printf+0x1e0>
        console_puts("(null)");
    8000052e:	00005517          	auipc	a0,0x5
    80000532:	19250513          	add	a0,a0,402 # 800056c0 <kalloc+0x102>
    80000536:	c1dff0ef          	jal	80000152 <console_puts>
            i++;
    8000053a:	8cce                	mv	s9,s3
    8000053c:	a02d                	j	80000566 <printf+0x1e0>
                        console_putc(va_arg(ap, int));
    8000053e:	f9843783          	ld	a5,-104(s0)
    80000542:	00878713          	add	a4,a5,8
    80000546:	f8e43c23          	sd	a4,-104(s0)
    8000054a:	0007c503          	lbu	a0,0(a5)
    8000054e:	bf1ff0ef          	jal	8000013e <console_putc>
            i++;
    80000552:	8cce                	mv	s9,s3
                        break;
    80000554:	a809                	j	80000566 <printf+0x1e0>
                        console_putc('%');
    80000556:	02500513          	li	a0,37
    8000055a:	be5ff0ef          	jal	8000013e <console_putc>
            i++;
    8000055e:	8cce                	mv	s9,s3
                        break;
    80000560:	a019                	j	80000566 <printf+0x1e0>
            console_putc(fmt[i]);
    80000562:	bddff0ef          	jal	8000013e <console_putc>
    for (int i = 0; fmt[i]; i++) {
    80000566:	2c85                	addw	s9,s9,1
    80000568:	019907b3          	add	a5,s2,s9
    8000056c:	0007c503          	lbu	a0,0(a5)
    80000570:	cd1d                	beqz	a0,800005ae <printf+0x228>
        if (fmt[i] == '%') {
    80000572:	ff4518e3          	bne	a0,s4,80000562 <printf+0x1dc>
            i++;
    80000576:	001c899b          	addw	s3,s9,1
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    8000057a:	013904b3          	add	s1,s2,s3
    8000057e:	0004c783          	lbu	a5,0(s1)
    80000582:	e5678ee3          	beq	a5,s6,800003de <printf+0x58>
                switch (fmt[i]) {
    80000586:	fd4788e3          	beq	a5,s4,80000556 <printf+0x1d0>
    8000058a:	f9d7871b          	addw	a4,a5,-99
    8000058e:	0ff77713          	zext.b	a4,a4
    80000592:	e4eaeae3          	bltu	s5,a4,800003e6 <printf+0x60>
    80000596:	f9d7879b          	addw	a5,a5,-99
    8000059a:	0ff7f713          	zext.b	a4,a5
    8000059e:	e4eae4e3          	bltu	s5,a4,800003e6 <printf+0x60>
    800005a2:	00271793          	sll	a5,a4,0x2
    800005a6:	97de                	add	a5,a5,s7
    800005a8:	439c                	lw	a5,0(a5)
    800005aa:	97de                	add	a5,a5,s7
    800005ac:	8782                	jr	a5
}
    800005ae:	4501                	li	a0,0
    800005b0:	60aa                	ld	ra,136(sp)
    800005b2:	640a                	ld	s0,128(sp)
    800005b4:	74e6                	ld	s1,120(sp)
    800005b6:	7946                	ld	s2,112(sp)
    800005b8:	79a6                	ld	s3,104(sp)
    800005ba:	7a06                	ld	s4,96(sp)
    800005bc:	6ae6                	ld	s5,88(sp)
    800005be:	6b46                	ld	s6,80(sp)
    800005c0:	6ba6                	ld	s7,72(sp)
    800005c2:	6c06                	ld	s8,64(sp)
    800005c4:	7ce2                	ld	s9,56(sp)
    800005c6:	6169                	add	sp,sp,208
    800005c8:	8082                	ret

00000000800005ca <sprintf>:
    }
    
    return count;
}

int sprintf(char *buf, const char *fmt, ...) {
    800005ca:	7155                	add	sp,sp,-208
    800005cc:	ed06                	sd	ra,152(sp)
    800005ce:	e922                	sd	s0,144(sp)
    800005d0:	e526                	sd	s1,136(sp)
    800005d2:	e14a                	sd	s2,128(sp)
    800005d4:	fcce                	sd	s3,120(sp)
    800005d6:	f8d2                	sd	s4,112(sp)
    800005d8:	f4d6                	sd	s5,104(sp)
    800005da:	f0da                	sd	s6,96(sp)
    800005dc:	ecde                	sd	s7,88(sp)
    800005de:	e8e2                	sd	s8,80(sp)
    800005e0:	e4e6                	sd	s9,72(sp)
    800005e2:	e0ea                	sd	s10,64(sp)
    800005e4:	1100                	add	s0,sp,160
    800005e6:	84aa                	mv	s1,a0
    800005e8:	e010                	sd	a2,0(s0)
    800005ea:	e414                	sd	a3,8(s0)
    800005ec:	e818                	sd	a4,16(s0)
    800005ee:	ec1c                	sd	a5,24(s0)
    800005f0:	03043023          	sd	a6,32(s0)
    800005f4:	03143423          	sd	a7,40(s0)
    va_list ap;
    va_start(ap, fmt);
    800005f8:	f8843c23          	sd	s0,-104(s0)
    
    int total_chars = 0;
    
    for (int i = 0; fmt[i]; i++) {
    800005fc:	0005c783          	lbu	a5,0(a1)
    80000600:	1c078c63          	beqz	a5,800007d8 <sprintf+0x20e>
    80000604:	89ae                	mv	s3,a1
    80000606:	4701                	li	a4,0
    int total_chars = 0;
    80000608:	4901                	li	s2,0
        if (fmt[i] == '%') {
    8000060a:	02500a13          	li	s4,37
            i++;
            if (fmt[i] == '\0') break;
            
            // 检查是否是lx格式
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    8000060e:	06c00b93          	li	s7,108
                uint64 num = va_arg(ap, uint64);
                int count = number64_to_buffer(num, 16, 0, buf);
                buf += count;
                total_chars += count;
            } else {
                switch (fmt[i]) {
    80000612:	06400a93          	li	s5,100
    80000616:	07300c93          	li	s9,115
    8000061a:	07800b13          	li	s6,120
    8000061e:	06300c13          	li	s8,99
    80000622:	aa1d                	j	80000758 <sprintf+0x18e>
            i++;
    80000624:	00170d1b          	addw	s10,a4,1
            if (fmt[i] == '\0') break;
    80000628:	01a986b3          	add	a3,s3,s10
    8000062c:	0006c783          	lbu	a5,0(a3)
    80000630:	1a078563          	beqz	a5,800007da <sprintf+0x210>
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    80000634:	03778b63          	beq	a5,s7,8000066a <sprintf+0xa0>
                switch (fmt[i]) {
    80000638:	0f578a63          	beq	a5,s5,8000072c <sprintf+0x162>
    8000063c:	0cfaf763          	bgeu	s5,a5,8000070a <sprintf+0x140>
    80000640:	13978363          	beq	a5,s9,80000766 <sprintf+0x19c>
    80000644:	03679763          	bne	a5,s6,80000672 <sprintf+0xa8>
                        buf += count;
                        total_chars += count;
                        break;
                    }
                    case 'x': {
                        int num = va_arg(ap, int);
    80000648:	f9843783          	ld	a5,-104(s0)
    8000064c:	00878713          	add	a4,a5,8
    80000650:	f8e43c23          	sd	a4,-104(s0)
                        int count = number_to_buffer(num, 16, 0, buf);
    80000654:	86a6                	mv	a3,s1
    80000656:	4601                	li	a2,0
    80000658:	45c1                	li	a1,16
    8000065a:	4388                	lw	a0,0(a5)
    8000065c:	bfbff0ef          	jal	80000256 <number_to_buffer>
                        buf += count;
    80000660:	94aa                	add	s1,s1,a0
                        total_chars += count;
    80000662:	0125093b          	addw	s2,a0,s2
            i++;
    80000666:	876a                	mv	a4,s10
                        break;
    80000668:	a0d5                	j	8000074c <sprintf+0x182>
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    8000066a:	0016c783          	lbu	a5,1(a3)
    8000066e:	01678e63          	beq	a5,s6,8000068a <sprintf+0xc0>
                        *buf++ = '%';
                        total_chars++;
                        break;
                    }
                    default: {
                        *buf++ = '%';
    80000672:	02500793          	li	a5,37
    80000676:	00f48023          	sb	a5,0(s1)
                        *buf++ = fmt[i];
    8000067a:	0006c783          	lbu	a5,0(a3)
    8000067e:	00f480a3          	sb	a5,1(s1)
                        total_chars += 2;
    80000682:	2909                	addw	s2,s2,2
            i++;
    80000684:	876a                	mv	a4,s10
                        *buf++ = fmt[i];
    80000686:	0489                	add	s1,s1,2
                        break;
    80000688:	a0d1                	j	8000074c <sprintf+0x182>
                i++; // 跳过'l'
    8000068a:	2709                	addw	a4,a4,2
                uint64 num = va_arg(ap, uint64);
    8000068c:	f9843783          	ld	a5,-104(s0)
    80000690:	00878693          	add	a3,a5,8
    80000694:	f8d43c23          	sd	a3,-104(s0)
    80000698:	639c                	ld	a5,0(a5)
    char digits[] = "0123456789abcdef";
    8000069a:	00005697          	auipc	a3,0x5
    8000069e:	00e68693          	add	a3,a3,14 # 800056a8 <kalloc+0xea>
    800006a2:	6290                	ld	a2,0(a3)
    800006a4:	f6c43023          	sd	a2,-160(s0)
    800006a8:	6690                	ld	a2,8(a3)
    800006aa:	f6c43423          	sd	a2,-152(s0)
    800006ae:	0106c683          	lbu	a3,16(a3)
    800006b2:	f6d40823          	sb	a3,-144(s0)
    800006b6:	f7840613          	add	a2,s0,-136
    } while (n > 0);
    800006ba:	45bd                	li	a1,15
        *ptr++ = digits[n % base];
    800006bc:	0605                	add	a2,a2,1
    800006be:	00f7f693          	and	a3,a5,15
    800006c2:	fa068693          	add	a3,a3,-96
    800006c6:	96a2                	add	a3,a3,s0
    800006c8:	fc06c683          	lbu	a3,-64(a3)
    800006cc:	fed60fa3          	sb	a3,-1(a2)
        n /= base;
    800006d0:	86be                	mv	a3,a5
    800006d2:	8391                	srl	a5,a5,0x4
    } while (n > 0);
    800006d4:	fed5e4e3          	bltu	a1,a3,800006bc <sprintf+0xf2>
    while (ptr > temp_buf) {
    800006d8:	f7840793          	add	a5,s0,-136
    800006dc:	02c7f563          	bgeu	a5,a2,80000706 <sprintf+0x13c>
    800006e0:	86a6                	mv	a3,s1
        *ptr++ = digits[n % base];
    800006e2:	87b2                	mv	a5,a2
    while (ptr > temp_buf) {
    800006e4:	f7840513          	add	a0,s0,-136
        *buf++ = *--ptr;
    800006e8:	17fd                	add	a5,a5,-1
    800006ea:	0685                	add	a3,a3,1
    800006ec:	0007c583          	lbu	a1,0(a5)
    800006f0:	feb68fa3          	sb	a1,-1(a3)
    while (ptr > temp_buf) {
    800006f4:	fea79ae3          	bne	a5,a0,800006e8 <sprintf+0x11e>
        count++;
    800006f8:	f7840793          	add	a5,s0,-136
    800006fc:	9e1d                	subw	a2,a2,a5
                buf += count;
    800006fe:	94b2                	add	s1,s1,a2
                total_chars += count;
    80000700:	00c9093b          	addw	s2,s2,a2
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    80000704:	a0a1                	j	8000074c <sprintf+0x182>
    while (ptr > temp_buf) {
    80000706:	4601                	li	a2,0
    80000708:	bfdd                	j	800006fe <sprintf+0x134>
                switch (fmt[i]) {
    8000070a:	0b478f63          	beq	a5,s4,800007c8 <sprintf+0x1fe>
    8000070e:	f78792e3          	bne	a5,s8,80000672 <sprintf+0xa8>
                        char c = va_arg(ap, int);
    80000712:	f9843783          	ld	a5,-104(s0)
    80000716:	00878713          	add	a4,a5,8
    8000071a:	f8e43c23          	sd	a4,-104(s0)
    8000071e:	439c                	lw	a5,0(a5)
    80000720:	00f48023          	sb	a5,0(s1)
                        total_chars++;
    80000724:	2905                	addw	s2,s2,1
            i++;
    80000726:	876a                	mv	a4,s10
                        *buf++ = c;
    80000728:	0485                	add	s1,s1,1
                        break;
    8000072a:	a00d                	j	8000074c <sprintf+0x182>
                        int num = va_arg(ap, int);
    8000072c:	f9843783          	ld	a5,-104(s0)
    80000730:	00878713          	add	a4,a5,8
    80000734:	f8e43c23          	sd	a4,-104(s0)
                        int count = number_to_buffer(num, 10, 1, buf);
    80000738:	86a6                	mv	a3,s1
    8000073a:	4605                	li	a2,1
    8000073c:	45a9                	li	a1,10
    8000073e:	4388                	lw	a0,0(a5)
    80000740:	b17ff0ef          	jal	80000256 <number_to_buffer>
                        buf += count;
    80000744:	94aa                	add	s1,s1,a0
                        total_chars += count;
    80000746:	0125093b          	addw	s2,a0,s2
            i++;
    8000074a:	876a                	mv	a4,s10
    for (int i = 0; fmt[i]; i++) {
    8000074c:	2705                	addw	a4,a4,1
    8000074e:	00e987b3          	add	a5,s3,a4
    80000752:	0007c783          	lbu	a5,0(a5)
    80000756:	c3d1                	beqz	a5,800007da <sprintf+0x210>
        if (fmt[i] == '%') {
    80000758:	ed4786e3          	beq	a5,s4,80000624 <sprintf+0x5a>
                    }
                }
            }
        } else {
            *buf++ = fmt[i];
    8000075c:	00f48023          	sb	a5,0(s1)
            total_chars++;
    80000760:	2905                	addw	s2,s2,1
            *buf++ = fmt[i];
    80000762:	0485                	add	s1,s1,1
    80000764:	b7e5                	j	8000074c <sprintf+0x182>
                        char *str = va_arg(ap, char*);
    80000766:	f9843783          	ld	a5,-104(s0)
    8000076a:	00878713          	add	a4,a5,8
    8000076e:	f8e43c23          	sd	a4,-104(s0)
    80000772:	6398                	ld	a4,0(a5)
    if (s == 0) {
    80000774:	c715                	beqz	a4,800007a0 <sprintf+0x1d6>
        while (*s) {
    80000776:	00074683          	lbu	a3,0(a4)
    8000077a:	85a6                	mv	a1,s1
    8000077c:	87a6                	mv	a5,s1
    int count = 0;
    8000077e:	4601                	li	a2,0
        while (*s) {
    80000780:	ca99                	beqz	a3,80000796 <sprintf+0x1cc>
            *buf++ = *s++;
    80000782:	0705                	add	a4,a4,1
    80000784:	00d78023          	sb	a3,0(a5)
        while (*s) {
    80000788:	00074683          	lbu	a3,0(a4)
    8000078c:	863e                	mv	a2,a5
    8000078e:	0785                	add	a5,a5,1
    80000790:	faed                	bnez	a3,80000782 <sprintf+0x1b8>
            count++;
    80000792:	9e0d                	subw	a2,a2,a1
    80000794:	2605                	addw	a2,a2,1
                        buf += count;
    80000796:	94b2                	add	s1,s1,a2
                        total_chars += count;
    80000798:	0126093b          	addw	s2,a2,s2
            i++;
    8000079c:	876a                	mv	a4,s10
                        break;
    8000079e:	b77d                	j	8000074c <sprintf+0x182>
        while (*null_str) {
    800007a0:	85a6                	mv	a1,s1
    if (s == 0) {
    800007a2:	8726                	mv	a4,s1
        while (*null_str) {
    800007a4:	02800613          	li	a2,40
        const char *null_str = "(null)";
    800007a8:	00005697          	auipc	a3,0x5
    800007ac:	f1868693          	add	a3,a3,-232 # 800056c0 <kalloc+0x102>
            *buf++ = *null_str++;
    800007b0:	0685                	add	a3,a3,1
    800007b2:	00c70023          	sb	a2,0(a4)
        while (*null_str) {
    800007b6:	0006c603          	lbu	a2,0(a3)
    800007ba:	87ba                	mv	a5,a4
    800007bc:	0705                	add	a4,a4,1
    800007be:	fa6d                	bnez	a2,800007b0 <sprintf+0x1e6>
            count++;
    800007c0:	9f8d                	subw	a5,a5,a1
    800007c2:	0017861b          	addw	a2,a5,1
    800007c6:	bfc1                	j	80000796 <sprintf+0x1cc>
                        *buf++ = '%';
    800007c8:	02500793          	li	a5,37
    800007cc:	00f48023          	sb	a5,0(s1)
                        total_chars++;
    800007d0:	2905                	addw	s2,s2,1
            i++;
    800007d2:	876a                	mv	a4,s10
                        *buf++ = '%';
    800007d4:	0485                	add	s1,s1,1
                        break;
    800007d6:	bf9d                	j	8000074c <sprintf+0x182>
    int total_chars = 0;
    800007d8:	4901                	li	s2,0
        }
    }
    
    *buf = '\0';
    800007da:	00048023          	sb	zero,0(s1)
    va_end(ap);
    return total_chars;
}
    800007de:	854a                	mv	a0,s2
    800007e0:	60ea                	ld	ra,152(sp)
    800007e2:	644a                	ld	s0,144(sp)
    800007e4:	64aa                	ld	s1,136(sp)
    800007e6:	690a                	ld	s2,128(sp)
    800007e8:	79e6                	ld	s3,120(sp)
    800007ea:	7a46                	ld	s4,112(sp)
    800007ec:	7aa6                	ld	s5,104(sp)
    800007ee:	7b06                	ld	s6,96(sp)
    800007f0:	6be6                	ld	s7,88(sp)
    800007f2:	6c46                	ld	s8,80(sp)
    800007f4:	6ca6                	ld	s9,72(sp)
    800007f6:	6d06                	ld	s10,64(sp)
    800007f8:	6169                	add	sp,sp,208
    800007fa:	8082                	ret

00000000800007fc <printf_color>:

// 彩色printf函数
int printf_color(int color, const char *fmt, ...) {
    800007fc:	7131                	add	sp,sp,-192
    800007fe:	e506                	sd	ra,136(sp)
    80000800:	e122                	sd	s0,128(sp)
    80000802:	fca6                	sd	s1,120(sp)
    80000804:	f8ca                	sd	s2,112(sp)
    80000806:	f4ce                	sd	s3,104(sp)
    80000808:	f0d2                	sd	s4,96(sp)
    8000080a:	ecd6                	sd	s5,88(sp)
    8000080c:	e8da                	sd	s6,80(sp)
    8000080e:	e4de                	sd	s7,72(sp)
    80000810:	e0e2                	sd	s8,64(sp)
    80000812:	fc66                	sd	s9,56(sp)
    80000814:	f86a                	sd	s10,48(sp)
    80000816:	0900                	add	s0,sp,144
    80000818:	892e                	mv	s2,a1
    8000081a:	e010                	sd	a2,0(s0)
    8000081c:	e414                	sd	a3,8(s0)
    8000081e:	e818                	sd	a4,16(s0)
    80000820:	ec1c                	sd	a5,24(s0)
    80000822:	03043023          	sd	a6,32(s0)
    80000826:	03143423          	sd	a7,40(s0)
    va_list ap;
    va_start(ap, fmt);
    8000082a:	f8843c23          	sd	s0,-104(s0)
    
    // 设置颜色
    console_set_color(color);
    8000082e:	9b7ff0ef          	jal	800001e4 <console_set_color>
    
    // 使用现有的printf逻辑进行格式化输出
    for (int i = 0; fmt[i]; i++) {
    80000832:	00094503          	lbu	a0,0(s2)
    80000836:	14050463          	beqz	a0,8000097e <printf_color+0x182>
    8000083a:	4481                	li	s1,0
        if (fmt[i] == '%') {
    8000083c:	02500a13          	li	s4,37
            i++;
            // 检查是否是lx格式
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    80000840:	06c00b93          	li	s7,108
                i++; // 跳过'l'
                print_number64(va_arg(ap, uint64), 16, 0);
            } else {
                switch (fmt[i]) {
    80000844:	06400a93          	li	s5,100
    80000848:	07300c93          	li	s9,115
    8000084c:	07800b13          	li	s6,120
    80000850:	06300c13          	li	s8,99
    80000854:	a0f5                	j	80000940 <printf_color+0x144>
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    80000856:	001d4783          	lbu	a5,1(s10)
    8000085a:	01678c63          	beq	a5,s6,80000872 <printf_color+0x76>
                    case '%': {
                        console_putc('%');
                        break;
                    }
                    default: {
                        console_putc('%');
    8000085e:	02500513          	li	a0,37
    80000862:	8ddff0ef          	jal	8000013e <console_putc>
                        console_putc(fmt[i]);
    80000866:	000d4503          	lbu	a0,0(s10)
    8000086a:	8d5ff0ef          	jal	8000013e <console_putc>
            i++;
    8000086e:	84ce                	mv	s1,s3
                        break;
    80000870:	a0d1                	j	80000934 <printf_color+0x138>
                i++; // 跳过'l'
    80000872:	2489                	addw	s1,s1,2
                print_number64(va_arg(ap, uint64), 16, 0);
    80000874:	f9843783          	ld	a5,-104(s0)
    80000878:	00878713          	add	a4,a5,8
    8000087c:	f8e43c23          	sd	a4,-104(s0)
    80000880:	639c                	ld	a5,0(a5)
    80000882:	f7840993          	add	s3,s0,-136
        *ptr++ = digits[n % base];
    80000886:	00005617          	auipc	a2,0x5
    8000088a:	e2260613          	add	a2,a2,-478 # 800056a8 <kalloc+0xea>
    } while (n > 0);
    8000088e:	46bd                	li	a3,15
        *ptr++ = digits[n % base];
    80000890:	0985                	add	s3,s3,1
    80000892:	00f7f713          	and	a4,a5,15
    80000896:	9732                	add	a4,a4,a2
    80000898:	00074703          	lbu	a4,0(a4)
    8000089c:	fee98fa3          	sb	a4,-1(s3)
        n /= base;
    800008a0:	873e                	mv	a4,a5
    800008a2:	8391                	srl	a5,a5,0x4
    } while (n > 0);
    800008a4:	fee6e6e3          	bltu	a3,a4,80000890 <printf_color+0x94>
    while (ptr > buf) {
    800008a8:	f7840793          	add	a5,s0,-136
    800008ac:	0937f463          	bgeu	a5,s3,80000934 <printf_color+0x138>
    800008b0:	8d3e                	mv	s10,a5
        console_putc(*--ptr);
    800008b2:	19fd                	add	s3,s3,-1
    800008b4:	0009c503          	lbu	a0,0(s3)
    800008b8:	887ff0ef          	jal	8000013e <console_putc>
    while (ptr > buf) {
    800008bc:	ffa99be3          	bne	s3,s10,800008b2 <printf_color+0xb6>
    800008c0:	a895                	j	80000934 <printf_color+0x138>
                switch (fmt[i]) {
    800008c2:	07478163          	beq	a5,s4,80000924 <printf_color+0x128>
    800008c6:	f9879ce3          	bne	a5,s8,8000085e <printf_color+0x62>
                        char c = va_arg(ap, int);
    800008ca:	f9843783          	ld	a5,-104(s0)
    800008ce:	00878713          	add	a4,a5,8
    800008d2:	f8e43c23          	sd	a4,-104(s0)
                        console_putc(c);
    800008d6:	0007c503          	lbu	a0,0(a5)
    800008da:	865ff0ef          	jal	8000013e <console_putc>
            i++;
    800008de:	84ce                	mv	s1,s3
                        break;
    800008e0:	a891                	j	80000934 <printf_color+0x138>
                        int num = va_arg(ap, int);
    800008e2:	f9843783          	ld	a5,-104(s0)
    800008e6:	00878713          	add	a4,a5,8
    800008ea:	f8e43c23          	sd	a4,-104(s0)
                        print_number(num, 10, 1);
    800008ee:	4605                	li	a2,1
    800008f0:	45a9                	li	a1,10
    800008f2:	4388                	lw	a0,0(a5)
    800008f4:	a01ff0ef          	jal	800002f4 <print_number>
            i++;
    800008f8:	84ce                	mv	s1,s3
                        break;
    800008fa:	a82d                	j	80000934 <printf_color+0x138>
                        char *str = va_arg(ap, char*);
    800008fc:	f9843783          	ld	a5,-104(s0)
    80000900:	00878713          	add	a4,a5,8
    80000904:	f8e43c23          	sd	a4,-104(s0)
    80000908:	6388                	ld	a0,0(a5)
    if (s == 0) {
    8000090a:	c509                	beqz	a0,80000914 <printf_color+0x118>
        console_puts(s);
    8000090c:	847ff0ef          	jal	80000152 <console_puts>
            i++;
    80000910:	84ce                	mv	s1,s3
    80000912:	a00d                	j	80000934 <printf_color+0x138>
        console_puts("(null)");
    80000914:	00005517          	auipc	a0,0x5
    80000918:	dac50513          	add	a0,a0,-596 # 800056c0 <kalloc+0x102>
    8000091c:	837ff0ef          	jal	80000152 <console_puts>
            i++;
    80000920:	84ce                	mv	s1,s3
    80000922:	a809                	j	80000934 <printf_color+0x138>
                        console_putc('%');
    80000924:	02500513          	li	a0,37
    80000928:	817ff0ef          	jal	8000013e <console_putc>
            i++;
    8000092c:	84ce                	mv	s1,s3
                        break;
    8000092e:	a019                	j	80000934 <printf_color+0x138>
                    }
                }
            }
        } else {
            console_putc(fmt[i]);
    80000930:	80fff0ef          	jal	8000013e <console_putc>
    for (int i = 0; fmt[i]; i++) {
    80000934:	2485                	addw	s1,s1,1
    80000936:	009907b3          	add	a5,s2,s1
    8000093a:	0007c503          	lbu	a0,0(a5)
    8000093e:	c121                	beqz	a0,8000097e <printf_color+0x182>
        if (fmt[i] == '%') {
    80000940:	ff4518e3          	bne	a0,s4,80000930 <printf_color+0x134>
            i++;
    80000944:	0014899b          	addw	s3,s1,1
            if (fmt[i] == 'l' && fmt[i+1] == 'x') {
    80000948:	01390d33          	add	s10,s2,s3
    8000094c:	000d4783          	lbu	a5,0(s10)
    80000950:	f17783e3          	beq	a5,s7,80000856 <printf_color+0x5a>
                switch (fmt[i]) {
    80000954:	f95787e3          	beq	a5,s5,800008e2 <printf_color+0xe6>
    80000958:	f6faf5e3          	bgeu	s5,a5,800008c2 <printf_color+0xc6>
    8000095c:	fb9780e3          	beq	a5,s9,800008fc <printf_color+0x100>
    80000960:	ef679fe3          	bne	a5,s6,8000085e <printf_color+0x62>
                        int num = va_arg(ap, int);
    80000964:	f9843783          	ld	a5,-104(s0)
    80000968:	00878713          	add	a4,a5,8
    8000096c:	f8e43c23          	sd	a4,-104(s0)
                        print_number(num, 16, 0);
    80000970:	4601                	li	a2,0
    80000972:	45c1                	li	a1,16
    80000974:	4388                	lw	a0,0(a5)
    80000976:	97fff0ef          	jal	800002f4 <print_number>
            i++;
    8000097a:	84ce                	mv	s1,s3
                        break;
    8000097c:	bf65                	j	80000934 <printf_color+0x138>
        }
    }
    
    // 重置颜色
    console_reset_color();
    8000097e:	891ff0ef          	jal	8000020e <console_reset_color>
    
    va_end(ap);
    return 0;
}
    80000982:	4501                	li	a0,0
    80000984:	60aa                	ld	ra,136(sp)
    80000986:	640a                	ld	s0,128(sp)
    80000988:	74e6                	ld	s1,120(sp)
    8000098a:	7946                	ld	s2,112(sp)
    8000098c:	79a6                	ld	s3,104(sp)
    8000098e:	7a06                	ld	s4,96(sp)
    80000990:	6ae6                	ld	s5,88(sp)
    80000992:	6b46                	ld	s6,80(sp)
    80000994:	6ba6                	ld	s7,72(sp)
    80000996:	6c06                	ld	s8,64(sp)
    80000998:	7ce2                	ld	s9,56(sp)
    8000099a:	7d42                	ld	s10,48(sp)
    8000099c:	6129                	add	sp,sp,192
    8000099e:	8082                	ret

00000000800009a0 <panic>:

// panic函数：打印错误信息并停止执行
void panic(const char *s) {
    800009a0:	1141                	add	sp,sp,-16
    800009a2:	e406                	sd	ra,8(sp)
    800009a4:	e022                	sd	s0,0(sp)
    800009a6:	0800                	add	s0,sp,16
    800009a8:	85aa                	mv	a1,a0
    printf("panic: %s\n", s);
    800009aa:	00005517          	auipc	a0,0x5
    800009ae:	d1e50513          	add	a0,a0,-738 # 800056c8 <kalloc+0x10a>
    800009b2:	9d5ff0ef          	jal	80000386 <printf>
    // 死循环，停止执行
    for(;;) {
        asm volatile("wfi");  // wait for interrupt
    800009b6:	10500073          	wfi
    for(;;) {
    800009ba:	bff5                	j	800009b6 <panic+0x16>

00000000800009bc <timerinit>:
  asm volatile("mret");
}
// ask each hart to generate timer interrupts.
void
timerinit()
{
    800009bc:	1141                	add	sp,sp,-16
    800009be:	e422                	sd	s0,8(sp)
    800009c0:	0800                	add	s0,sp,16
#define MIE_STIE (1L << 5)  // supervisor timer
static inline uint64
r_mie()
{
  uint64 x;
  asm volatile("csrr %0, mie" : "=r" (x) );
    800009c2:	304027f3          	csrr	a5,mie
  // enable supervisor-mode timer interrupts.
  w_mie(r_mie() | MIE_STIE);
    800009c6:	0207e793          	or	a5,a5,32
}

static inline void 
w_mie(uint64 x)
{
  asm volatile("csrw mie, %0" : : "r" (x));
    800009ca:	30479073          	csrw	mie,a5
static inline uint64
r_menvcfg()
{
  uint64 x;
  // asm volatile("csrr %0, menvcfg" : "=r" (x) );
  asm volatile("csrr %0, 0x30a" : "=r" (x) );
    800009ce:	30a027f3          	csrr	a5,0x30a
  
  // enable the sstc extension (i.e. stimecmp).
  w_menvcfg(r_menvcfg() | (1L << 63)); 
    800009d2:	577d                	li	a4,-1
    800009d4:	177e                	sll	a4,a4,0x3f
    800009d6:	8fd9                	or	a5,a5,a4

static inline void 
w_menvcfg(uint64 x)
{
  // asm volatile("csrw menvcfg, %0" : : "r" (x));
  asm volatile("csrw 0x30a, %0" : : "r" (x));
    800009d8:	30a79073          	csrw	0x30a,a5

static inline uint64
r_mcounteren()
{
  uint64 x;
  asm volatile("csrr %0, mcounteren" : "=r" (x) );
    800009dc:	306027f3          	csrr	a5,mcounteren
  
  // allow supervisor to use stimecmp and time.
  w_mcounteren(r_mcounteren() | 2);
    800009e0:	0027e793          	or	a5,a5,2
  asm volatile("csrw mcounteren, %0" : : "r" (x));
    800009e4:	30679073          	csrw	mcounteren,a5
// machine-mode cycle counter
static inline uint64
r_time()
{
  uint64 x;
  asm volatile("csrr %0, time" : "=r" (x) );
    800009e8:	c01027f3          	rdtime	a5
  
  // ask for the very first timer interrupt.
  w_stimecmp(r_time() + 1000000);
    800009ec:	000f4737          	lui	a4,0xf4
    800009f0:	24070713          	add	a4,a4,576 # f4240 <_entry-0x7ff0bdc0>
    800009f4:	97ba                	add	a5,a5,a4
   asm volatile("csrw 0x14d, %0" : : "r" (x));
    800009f6:	14d79073          	csrw	stimecmp,a5
}
    800009fa:	6422                	ld	s0,8(sp)
    800009fc:	0141                	add	sp,sp,16
    800009fe:	8082                	ret

0000000080000a00 <start>:
{
    80000a00:	1141                	add	sp,sp,-16
    80000a02:	e406                	sd	ra,8(sp)
    80000a04:	e022                	sd	s0,0(sp)
    80000a06:	0800                	add	s0,sp,16
  asm volatile("csrr %0, mstatus" : "=r" (x) );
    80000a08:	300027f3          	csrr	a5,mstatus
  x &= ~MSTATUS_MPP_MASK;
    80000a0c:	7779                	lui	a4,0xffffe
    80000a0e:	7ff70713          	add	a4,a4,2047 # ffffffffffffe7ff <stack_top+0xffffffff7ffe47ef>
    80000a12:	8ff9                	and	a5,a5,a4
  x |= MSTATUS_MPP_S;
    80000a14:	6705                	lui	a4,0x1
    80000a16:	80070713          	add	a4,a4,-2048 # 800 <_entry-0x7ffff800>
    80000a1a:	8fd9                	or	a5,a5,a4
  asm volatile("csrw mstatus, %0" : : "r" (x));
    80000a1c:	30079073          	csrw	mstatus,a5
  asm volatile("csrw mepc, %0" : : "r" (x));
    80000a20:	fffff797          	auipc	a5,0xfffff
    80000a24:	61078793          	add	a5,a5,1552 # 80000030 <main>
    80000a28:	34179073          	csrw	mepc,a5
  asm volatile("csrw satp, %0" : : "r" (x));
    80000a2c:	4781                	li	a5,0
    80000a2e:	18079073          	csrw	satp,a5
  asm volatile("csrw medeleg, %0" : : "r" (x));
    80000a32:	67c1                	lui	a5,0x10
    80000a34:	17fd                	add	a5,a5,-1 # ffff <_entry-0x7fff0001>
    80000a36:	30279073          	csrw	medeleg,a5
  asm volatile("csrw mideleg, %0" : : "r" (x));
    80000a3a:	30379073          	csrw	mideleg,a5
  asm volatile("csrr %0, sie" : "=r" (x) );
    80000a3e:	104027f3          	csrr	a5,sie
  w_sie(r_sie() | SIE_SEIE | SIE_STIE);
    80000a42:	2207e793          	or	a5,a5,544
  asm volatile("csrw sie, %0" : : "r" (x));
    80000a46:	10479073          	csrw	sie,a5
  asm volatile("csrw pmpaddr0, %0" : : "r" (x));
    80000a4a:	57fd                	li	a5,-1
    80000a4c:	83a9                	srl	a5,a5,0xa
    80000a4e:	3b079073          	csrw	pmpaddr0,a5
  asm volatile("csrw pmpcfg0, %0" : : "r" (x));
    80000a52:	47bd                	li	a5,15
    80000a54:	3a079073          	csrw	pmpcfg0,a5
    timerinit();
    80000a58:	f65ff0ef          	jal	800009bc <timerinit>
  asm volatile("mret");
    80000a5c:	30200073          	mret
}
    80000a60:	60a2                	ld	ra,8(sp)
    80000a62:	6402                	ld	s0,0(sp)
    80000a64:	0141                	add	sp,sp,16
    80000a66:	8082                	ret

0000000080000a68 <pop_page>:
    r->next = freelist.head;
    freelist.head = r;
    freelist.free_pages++;
}

static void *pop_page(void) {
    80000a68:	1141                	add	sp,sp,-16
    80000a6a:	e422                	sd	s0,8(sp)
    80000a6c:	0800                	add	s0,sp,16
    struct run *r = freelist.head;
    80000a6e:	00006517          	auipc	a0,0x6
    80000a72:	c6253503          	ld	a0,-926(a0) # 800066d0 <freelist>
    if (!r) return 0;
    80000a76:	c911                	beqz	a0,80000a8a <pop_page+0x22>
    freelist.head = r->next;
    80000a78:	00006797          	auipc	a5,0x6
    80000a7c:	c5878793          	add	a5,a5,-936 # 800066d0 <freelist>
    80000a80:	6118                	ld	a4,0(a0)
    80000a82:	e398                	sd	a4,0(a5)
    freelist.free_pages--;
    80000a84:	6798                	ld	a4,8(a5)
    80000a86:	177d                	add	a4,a4,-1
    80000a88:	e798                	sd	a4,8(a5)
    return (void *)r;
}
    80000a8a:	6422                	ld	s0,8(sp)
    80000a8c:	0141                	add	sp,sp,16
    80000a8e:	8082                	ret

0000000080000a90 <pmm_init>:

void pmm_init(void) {
    80000a90:	1141                	add	sp,sp,-16
    80000a92:	e422                	sd	s0,8(sp)
    80000a94:	0800                	add	s0,sp,16
      // 从内核镜像末尾按页对齐开始，直到 PHYSTOP 建立空闲页链表
    uint64 pa_start = PGROUNDUP((uint64)end);
    80000a96:	00019797          	auipc	a5,0x19
    80000a9a:	57978793          	add	a5,a5,1401 # 8001a00f <end+0xfff>
    80000a9e:	777d                	lui	a4,0xfffff
    80000aa0:	8ff9                	and	a5,a5,a4
    uint64 pa_end = PHYSTOP;

    /// 逐页入链
    for (uint64 pa = pa_start; pa + PGSIZE <= pa_end; pa += PGSIZE) {
    80000aa2:	6685                	lui	a3,0x1
    80000aa4:	96be                	add	a3,a3,a5
    80000aa6:	4745                	li	a4,17
    80000aa8:	076e                	sll	a4,a4,0x1b
    80000aaa:	04d76363          	bltu	a4,a3,80000af0 <pmm_init+0x60>
    80000aae:	00006717          	auipc	a4,0x6
    80000ab2:	c2270713          	add	a4,a4,-990 # 800066d0 <freelist>
    80000ab6:	6310                	ld	a2,0(a4)
    80000ab8:	6718                	ld	a4,8(a4)
    80000aba:	000886b7          	lui	a3,0x88
    80000abe:	16fd                	add	a3,a3,-1 # 87fff <_entry-0x7ff78001>
    80000ac0:	06b2                	sll	a3,a3,0xc
    80000ac2:	8e9d                	sub	a3,a3,a5
    80000ac4:	82b1                	srl	a3,a3,0xc
    80000ac6:	00170593          	add	a1,a4,1
    80000aca:	96ae                	add	a3,a3,a1
    80000acc:	6505                	lui	a0,0x1
        push_page((void *)pa);
    80000ace:	85b2                	mv	a1,a2
    80000ad0:	863e                	mv	a2,a5
    r->next = freelist.head;
    80000ad2:	e38c                	sd	a1,0(a5)
    freelist.free_pages++;
    80000ad4:	0705                	add	a4,a4,1
    for (uint64 pa = pa_start; pa + PGSIZE <= pa_end; pa += PGSIZE) {
    80000ad6:	97aa                	add	a5,a5,a0
    80000ad8:	fed71be3          	bne	a4,a3,80000ace <pmm_init+0x3e>
    80000adc:	00006697          	auipc	a3,0x6
    80000ae0:	bf468693          	add	a3,a3,-1036 # 800066d0 <freelist>
    80000ae4:	000887b7          	lui	a5,0x88
    80000ae8:	17fd                	add	a5,a5,-1 # 87fff <_entry-0x7ff78001>
    80000aea:	07b2                	sll	a5,a5,0xc
    80000aec:	e29c                	sd	a5,0(a3)
    80000aee:	e698                	sd	a4,8(a3)
    }
}
    80000af0:	6422                	ld	s0,8(sp)
    80000af2:	0141                	add	sp,sp,16
    80000af4:	8082                	ret

0000000080000af6 <alloc_page>:

void *alloc_page(void) {
    80000af6:	1141                	add	sp,sp,-16
    80000af8:	e406                	sd	ra,8(sp)
    80000afa:	e022                	sd	s0,0(sp)
    80000afc:	0800                	add	s0,sp,16
    return pop_page();
    80000afe:	f6bff0ef          	jal	80000a68 <pop_page>
}
    80000b02:	60a2                	ld	ra,8(sp)
    80000b04:	6402                	ld	s0,0(sp)
    80000b06:	0141                	add	sp,sp,16
    80000b08:	8082                	ret

0000000080000b0a <free_page>:

void free_page(void *pa) {
    80000b0a:	1141                	add	sp,sp,-16
    80000b0c:	e422                	sd	s0,8(sp)
    80000b0e:	0800                	add	s0,sp,16
    if (pa == 0) return;
    80000b10:	c115                	beqz	a0,80000b34 <free_page+0x2a>
    return (addr & (PGSIZE - 1)) == 0;
    80000b12:	03451793          	sll	a5,a0,0x34
    uint64 addr = (uint64)pa;
      // 基本校验：页对齐、地址范围
    if (!is_page_aligned(addr)) return;
    80000b16:	ef99                	bnez	a5,80000b34 <free_page+0x2a>
    if (addr < PGROUNDUP((uint64)end) || addr + PGSIZE > PHYSTOP) return;
    80000b18:	00019797          	auipc	a5,0x19
    80000b1c:	4f778793          	add	a5,a5,1271 # 8001a00f <end+0xfff>
    80000b20:	76fd                	lui	a3,0xfffff
    80000b22:	8ff5                	and	a5,a5,a3
    80000b24:	00f56863          	bltu	a0,a5,80000b34 <free_page+0x2a>
    80000b28:	6705                	lui	a4,0x1
    80000b2a:	972a                	add	a4,a4,a0
    80000b2c:	47c5                	li	a5,17
    80000b2e:	07ee                	sll	a5,a5,0x1b
    80000b30:	00e7f563          	bgeu	a5,a4,80000b3a <free_page+0x30>
    push_page(pa);
}
    80000b34:	6422                	ld	s0,8(sp)
    80000b36:	0141                	add	sp,sp,16
    80000b38:	8082                	ret
    r->next = freelist.head;
    80000b3a:	00006797          	auipc	a5,0x6
    80000b3e:	b9678793          	add	a5,a5,-1130 # 800066d0 <freelist>
    80000b42:	6398                	ld	a4,0(a5)
    80000b44:	e118                	sd	a4,0(a0)
    freelist.head = r;
    80000b46:	e388                	sd	a0,0(a5)
    freelist.free_pages++;
    80000b48:	6798                	ld	a4,8(a5)
    80000b4a:	0705                	add	a4,a4,1 # 1001 <_entry-0x7fffefff>
    80000b4c:	e798                	sd	a4,8(a5)
}
    80000b4e:	b7dd                	j	80000b34 <free_page+0x2a>

0000000080000b50 <alloc_pages>:

void *alloc_pages(int n) {
    80000b50:	dc010113          	add	sp,sp,-576
    80000b54:	22113c23          	sd	ra,568(sp)
    80000b58:	22813823          	sd	s0,560(sp)
    80000b5c:	22913423          	sd	s1,552(sp)
    80000b60:	23213023          	sd	s2,544(sp)
    80000b64:	21313c23          	sd	s3,536(sp)
    80000b68:	21413823          	sd	s4,528(sp)
    80000b6c:	21513423          	sd	s5,520(sp)
    80000b70:	0480                	add	s0,sp,576
    if (n <= 0) return 0;
    80000b72:	06a05263          	blez	a0,80000bd6 <alloc_pages+0x86>
    80000b76:	8a2a                	mv	s4,a0
    if (n == 1) return alloc_page();
    80000b78:	4785                	li	a5,1
    80000b7a:	00f50b63          	beq	a0,a5,80000b90 <alloc_pages+0x40>

     // 简单实现：循环申请 n 次单页，不保证物理连续；若失败则回滚
    void *first = 0;
    void *saved[64];
    if (n > (int)(sizeof(saved)/sizeof(saved[0]))) return 0;
    80000b7e:	04000793          	li	a5,64
    80000b82:	04a7cc63          	blt	a5,a0,80000bda <alloc_pages+0x8a>
    80000b86:	dc040993          	add	s3,s0,-576
    int i = 0;
    80000b8a:	4901                	li	s2,0
    void *first = 0;
    80000b8c:	4a81                	li	s5,0
    80000b8e:	a8a9                	j	80000be8 <alloc_pages+0x98>
    return pop_page();
    80000b90:	ed9ff0ef          	jal	80000a68 <pop_page>
    80000b94:	8aaa                	mv	s5,a0
    if (n == 1) return alloc_page();
    80000b96:	a0ad                	j	80000c00 <alloc_pages+0xb0>
        void *p = alloc_page();
        if (!p) break;
        saved[i] = p;
        if (i == 0) first = p;
    }
    if (i != n) {
    80000b98:	072a0463          	beq	s4,s2,80000c00 <alloc_pages+0xb0>
        while (i-- > 0) free_page(saved[i]);
    80000b9c:	05205163          	blez	s2,80000bde <alloc_pages+0x8e>
    80000ba0:	00391713          	sll	a4,s2,0x3
    80000ba4:	fc070793          	add	a5,a4,-64
    80000ba8:	008789b3          	add	s3,a5,s0
    80000bac:	df898993          	add	s3,s3,-520
    80000bb0:	db040793          	add	a5,s0,-592
    80000bb4:	97ba                	add	a5,a5,a4
    80000bb6:	397d                	addw	s2,s2,-1
    80000bb8:	02091713          	sll	a4,s2,0x20
    80000bbc:	01d75913          	srl	s2,a4,0x1d
    80000bc0:	41278933          	sub	s2,a5,s2
    80000bc4:	0009b503          	ld	a0,0(s3)
    80000bc8:	f43ff0ef          	jal	80000b0a <free_page>
    80000bcc:	19e1                	add	s3,s3,-8
    80000bce:	ff299be3          	bne	s3,s2,80000bc4 <alloc_pages+0x74>
        return 0;
    80000bd2:	8aa6                	mv	s5,s1
    80000bd4:	a035                	j	80000c00 <alloc_pages+0xb0>
    if (n <= 0) return 0;
    80000bd6:	4a81                	li	s5,0
    80000bd8:	a025                	j	80000c00 <alloc_pages+0xb0>
    if (n > (int)(sizeof(saved)/sizeof(saved[0]))) return 0;
    80000bda:	4a81                	li	s5,0
    80000bdc:	a015                	j	80000c00 <alloc_pages+0xb0>
        return 0;
    80000bde:	8aaa                	mv	s5,a0
    80000be0:	a005                	j	80000c00 <alloc_pages+0xb0>
    for (; i < n; ++i) {
    80000be2:	2905                	addw	s2,s2,1
    80000be4:	09a1                	add	s3,s3,8
        if (i == 0) first = p;
    80000be6:	8aaa                	mv	s5,a0
    return pop_page();
    80000be8:	e81ff0ef          	jal	80000a68 <pop_page>
    80000bec:	84aa                	mv	s1,a0
        if (!p) break;
    80000bee:	d54d                	beqz	a0,80000b98 <alloc_pages+0x48>
        saved[i] = p;
    80000bf0:	00a9b023          	sd	a0,0(s3)
        if (i == 0) first = p;
    80000bf4:	fe0907e3          	beqz	s2,80000be2 <alloc_pages+0x92>
    for (; i < n; ++i) {
    80000bf8:	2905                	addw	s2,s2,1
    80000bfa:	09a1                	add	s3,s3,8
    80000bfc:	ff2a16e3          	bne	s4,s2,80000be8 <alloc_pages+0x98>
    }
    return first;
}
    80000c00:	8556                	mv	a0,s5
    80000c02:	23813083          	ld	ra,568(sp)
    80000c06:	23013403          	ld	s0,560(sp)
    80000c0a:	22813483          	ld	s1,552(sp)
    80000c0e:	22013903          	ld	s2,544(sp)
    80000c12:	21813983          	ld	s3,536(sp)
    80000c16:	21013a03          	ld	s4,528(sp)
    80000c1a:	20813a83          	ld	s5,520(sp)
    80000c1e:	24010113          	add	sp,sp,576
    80000c22:	8082                	ret

0000000080000c24 <pmm_free_pages>:

size_t pmm_free_pages(void) {
    80000c24:	1141                	add	sp,sp,-16
    80000c26:	e422                	sd	s0,8(sp)
    80000c28:	0800                	add	s0,sp,16
    return freelist.free_pages;
}
    80000c2a:	00006517          	auipc	a0,0x6
    80000c2e:	aae53503          	ld	a0,-1362(a0) # 800066d8 <freelist+0x8>
    80000c32:	6422                	ld	s0,8(sp)
    80000c34:	0141                	add	sp,sp,16
    80000c36:	8082                	ret

0000000080000c38 <walk_inner>:
    return (addr & (PGSIZE - 1)) == 0;
}

static pte_t* walk_inner(pagetable_t pt, uint64 va, int alloc) {
    // 仅支持 39-bit VA
    if (va >> 39) return 0;
    80000c38:	0275d793          	srl	a5,a1,0x27
    80000c3c:	e3d9                	bnez	a5,80000cc2 <walk_inner+0x8a>
static pte_t* walk_inner(pagetable_t pt, uint64 va, int alloc) {
    80000c3e:	7139                	add	sp,sp,-64
    80000c40:	fc06                	sd	ra,56(sp)
    80000c42:	f822                	sd	s0,48(sp)
    80000c44:	f426                	sd	s1,40(sp)
    80000c46:	f04a                	sd	s2,32(sp)
    80000c48:	ec4e                	sd	s3,24(sp)
    80000c4a:	e852                	sd	s4,16(sp)
    80000c4c:	e456                	sd	s5,8(sp)
    80000c4e:	0080                	add	s0,sp,64
    80000c50:	84ae                	mv	s1,a1
    80000c52:	89b2                	mv	s3,a2
    80000c54:	4979                	li	s2,30
    pagetable_t pagetable = pt;
    for (int level = 2; level > 0; level--) {
    80000c56:	4a31                	li	s4,12
        uint64 idx = VPN_MASK(va, level);
    80000c58:	0124dab3          	srl	s5,s1,s2
    80000c5c:	1ffafa93          	and	s5,s5,511
        pte_t *pte = &pagetable[idx];
    80000c60:	0a8e                	sll	s5,s5,0x3
    80000c62:	9aaa                	add	s5,s5,a0
        if (*pte & PTE_V) {
    80000c64:	000ab503          	ld	a0,0(s5)
    80000c68:	00157793          	and	a5,a0,1
    80000c6c:	c78d                	beqz	a5,80000c96 <walk_inner+0x5e>
            // 前进到下一级页表
            pagetable = (pagetable_t)PTE2PA(*pte);
    80000c6e:	8129                	srl	a0,a0,0xa
    80000c70:	0532                	sll	a0,a0,0xc
    for (int level = 2; level > 0; level--) {
    80000c72:	395d                	addw	s2,s2,-9
    80000c74:	ff4912e3          	bne	s2,s4,80000c58 <walk_inner+0x20>
            *pte = PA2PTE(newpage) | PTE_V;
            pagetable = (pagetable_t)newpage;
        }
    }
    // 到达最低级
    return &pagetable[VPN_MASK(va, 0)];
    80000c78:	00c4d793          	srl	a5,s1,0xc
    80000c7c:	1ff7f793          	and	a5,a5,511
    80000c80:	078e                	sll	a5,a5,0x3
    80000c82:	953e                	add	a0,a0,a5
}
    80000c84:	70e2                	ld	ra,56(sp)
    80000c86:	7442                	ld	s0,48(sp)
    80000c88:	74a2                	ld	s1,40(sp)
    80000c8a:	7902                	ld	s2,32(sp)
    80000c8c:	69e2                	ld	s3,24(sp)
    80000c8e:	6a42                	ld	s4,16(sp)
    80000c90:	6aa2                	ld	s5,8(sp)
    80000c92:	6121                	add	sp,sp,64
    80000c94:	8082                	ret
            if (!alloc) return 0;
    80000c96:	02098863          	beqz	s3,80000cc6 <walk_inner+0x8e>
            void *newpage = alloc_page();
    80000c9a:	e5dff0ef          	jal	80000af6 <alloc_page>
            if (!newpage) return 0;
    80000c9e:	d17d                	beqz	a0,80000c84 <walk_inner+0x4c>
    80000ca0:	86aa                	mv	a3,a0
    80000ca2:	6705                	lui	a4,0x1
    80000ca4:	972a                	add	a4,a4,a0
    80000ca6:	87aa                	mv	a5,a0
            for (int i = 0; i < 512; ++i) ((uint64*)newpage)[i] = 0;
    80000ca8:	0007b023          	sd	zero,0(a5)
    80000cac:	07a1                	add	a5,a5,8
    80000cae:	fee79de3          	bne	a5,a4,80000ca8 <walk_inner+0x70>
            *pte = PA2PTE(newpage) | PTE_V;
    80000cb2:	00c6d793          	srl	a5,a3,0xc
    80000cb6:	07aa                	sll	a5,a5,0xa
    80000cb8:	0017e793          	or	a5,a5,1
    80000cbc:	00fab023          	sd	a5,0(s5)
            pagetable = (pagetable_t)newpage;
    80000cc0:	bf4d                	j	80000c72 <walk_inner+0x3a>
    if (va >> 39) return 0;
    80000cc2:	4501                	li	a0,0
}
    80000cc4:	8082                	ret
            if (!alloc) return 0;
    80000cc6:	4501                	li	a0,0
    80000cc8:	bf75                	j	80000c84 <walk_inner+0x4c>

0000000080000cca <free_walk>:
    for (int i = 0; i < 512; ++i) ((uint64*)p)[i] = 0;
    return (pagetable_t)p;
}

static void free_walk(pagetable_t pt, int level) {
    if (!pt) return;
    80000cca:	c12d                	beqz	a0,80000d2c <free_walk+0x62>
    if (level == 0) return; // L0 由上层根据映射拆除后释放整页表
    80000ccc:	c1a5                	beqz	a1,80000d2c <free_walk+0x62>
static void free_walk(pagetable_t pt, int level) {
    80000cce:	7139                	add	sp,sp,-64
    80000cd0:	fc06                	sd	ra,56(sp)
    80000cd2:	f822                	sd	s0,48(sp)
    80000cd4:	f426                	sd	s1,40(sp)
    80000cd6:	f04a                	sd	s2,32(sp)
    80000cd8:	ec4e                	sd	s3,24(sp)
    80000cda:	e852                	sd	s4,16(sp)
    80000cdc:	e456                	sd	s5,8(sp)
    80000cde:	0080                	add	s0,sp,64
    80000ce0:	84aa                	mv	s1,a0
    80000ce2:	6785                	lui	a5,0x1
    80000ce4:	00f509b3          	add	s3,a0,a5
    for (int i = 0; i < 512; ++i) {
        pte_t pte = pt[i];
        if ((pte & PTE_V) && !(pte & (PTE_R|PTE_W|PTE_X))) {
    80000ce8:	4a05                	li	s4,1
            // 指向下一级页表
            pagetable_t child = (pagetable_t)PTE2PA(pte);
            free_walk(child, level - 1);
    80000cea:	fff58a9b          	addw	s5,a1,-1
    80000cee:	a021                	j	80000cf6 <free_walk+0x2c>
    for (int i = 0; i < 512; ++i) {
    80000cf0:	04a1                	add	s1,s1,8
    80000cf2:	03348463          	beq	s1,s3,80000d1a <free_walk+0x50>
        pte_t pte = pt[i];
    80000cf6:	609c                	ld	a5,0(s1)
        if ((pte & PTE_V) && !(pte & (PTE_R|PTE_W|PTE_X))) {
    80000cf8:	00f7f713          	and	a4,a5,15
    80000cfc:	ff471ae3          	bne	a4,s4,80000cf0 <free_walk+0x26>
            pagetable_t child = (pagetable_t)PTE2PA(pte);
    80000d00:	83a9                	srl	a5,a5,0xa
    80000d02:	00c79913          	sll	s2,a5,0xc
            free_walk(child, level - 1);
    80000d06:	85d6                	mv	a1,s5
    80000d08:	854a                	mv	a0,s2
    80000d0a:	fc1ff0ef          	jal	80000cca <free_walk>
            pt[i] = 0;
    80000d0e:	0004b023          	sd	zero,0(s1)
            free_page(child);
    80000d12:	854a                	mv	a0,s2
    80000d14:	df7ff0ef          	jal	80000b0a <free_page>
    80000d18:	bfe1                	j	80000cf0 <free_walk+0x26>
        }
    }
}
    80000d1a:	70e2                	ld	ra,56(sp)
    80000d1c:	7442                	ld	s0,48(sp)
    80000d1e:	74a2                	ld	s1,40(sp)
    80000d20:	7902                	ld	s2,32(sp)
    80000d22:	69e2                	ld	s3,24(sp)
    80000d24:	6a42                	ld	s4,16(sp)
    80000d26:	6aa2                	ld	s5,8(sp)
    80000d28:	6121                	add	sp,sp,64
    80000d2a:	8082                	ret
    80000d2c:	8082                	ret

0000000080000d2e <walk_create>:
pte_t* walk_create(pagetable_t pt, uint64 va) { return walk_inner(pt, va, 1); }
    80000d2e:	1141                	add	sp,sp,-16
    80000d30:	e406                	sd	ra,8(sp)
    80000d32:	e022                	sd	s0,0(sp)
    80000d34:	0800                	add	s0,sp,16
    80000d36:	4605                	li	a2,1
    80000d38:	f01ff0ef          	jal	80000c38 <walk_inner>
    80000d3c:	60a2                	ld	ra,8(sp)
    80000d3e:	6402                	ld	s0,0(sp)
    80000d40:	0141                	add	sp,sp,16
    80000d42:	8082                	ret

0000000080000d44 <walk_lookup>:
pte_t* walk_lookup(pagetable_t pt, uint64 va) { return walk_inner(pt, va, 0); }
    80000d44:	1141                	add	sp,sp,-16
    80000d46:	e406                	sd	ra,8(sp)
    80000d48:	e022                	sd	s0,0(sp)
    80000d4a:	0800                	add	s0,sp,16
    80000d4c:	4601                	li	a2,0
    80000d4e:	eebff0ef          	jal	80000c38 <walk_inner>
    80000d52:	60a2                	ld	ra,8(sp)
    80000d54:	6402                	ld	s0,0(sp)
    80000d56:	0141                	add	sp,sp,16
    80000d58:	8082                	ret

0000000080000d5a <create_pagetable>:
pagetable_t create_pagetable(void) {
    80000d5a:	1141                	add	sp,sp,-16
    80000d5c:	e406                	sd	ra,8(sp)
    80000d5e:	e022                	sd	s0,0(sp)
    80000d60:	0800                	add	s0,sp,16
    void *p = alloc_page();
    80000d62:	d95ff0ef          	jal	80000af6 <alloc_page>
    if (!p) return 0;
    80000d66:	c909                	beqz	a0,80000d78 <create_pagetable+0x1e>
    80000d68:	87aa                	mv	a5,a0
    80000d6a:	6705                	lui	a4,0x1
    80000d6c:	972a                	add	a4,a4,a0
    for (int i = 0; i < 512; ++i) ((uint64*)p)[i] = 0;
    80000d6e:	0007b023          	sd	zero,0(a5) # 1000 <_entry-0x7ffff000>
    80000d72:	07a1                	add	a5,a5,8
    80000d74:	fee79de3          	bne	a5,a4,80000d6e <create_pagetable+0x14>
}
    80000d78:	60a2                	ld	ra,8(sp)
    80000d7a:	6402                	ld	s0,0(sp)
    80000d7c:	0141                	add	sp,sp,16
    80000d7e:	8082                	ret

0000000080000d80 <destroy_pagetable>:

void destroy_pagetable(pagetable_t pt) {
    if (!pt) return;
    80000d80:	c115                	beqz	a0,80000da4 <destroy_pagetable+0x24>
void destroy_pagetable(pagetable_t pt) {
    80000d82:	1101                	add	sp,sp,-32
    80000d84:	ec06                	sd	ra,24(sp)
    80000d86:	e822                	sd	s0,16(sp)
    80000d88:	e426                	sd	s1,8(sp)
    80000d8a:	1000                	add	s0,sp,32
    80000d8c:	84aa                	mv	s1,a0
    free_walk(pt, 2);
    80000d8e:	4589                	li	a1,2
    80000d90:	f3bff0ef          	jal	80000cca <free_walk>
    free_page(pt);
    80000d94:	8526                	mv	a0,s1
    80000d96:	d75ff0ef          	jal	80000b0a <free_page>
}
    80000d9a:	60e2                	ld	ra,24(sp)
    80000d9c:	6442                	ld	s0,16(sp)
    80000d9e:	64a2                	ld	s1,8(sp)
    80000da0:	6105                	add	sp,sp,32
    80000da2:	8082                	ret
    80000da4:	8082                	ret

0000000080000da6 <map_page>:

int map_page(pagetable_t pt, uint64 va, uint64 pa, int perm) {
    if (!is_page_aligned(va) || !is_page_aligned(pa)) return -1;
    80000da6:	00c5e7b3          	or	a5,a1,a2
    80000daa:	17d2                	sll	a5,a5,0x34
    80000dac:	e3b9                	bnez	a5,80000df2 <map_page+0x4c>
int map_page(pagetable_t pt, uint64 va, uint64 pa, int perm) {
    80000dae:	1101                	add	sp,sp,-32
    80000db0:	ec06                	sd	ra,24(sp)
    80000db2:	e822                	sd	s0,16(sp)
    80000db4:	e426                	sd	s1,8(sp)
    80000db6:	e04a                	sd	s2,0(sp)
    80000db8:	1000                	add	s0,sp,32
    80000dba:	84b2                	mv	s1,a2
    80000dbc:	8936                	mv	s2,a3
    pte_t *pte = walk_create(pt, va);
    80000dbe:	f71ff0ef          	jal	80000d2e <walk_create>
    if (!pte) return -1;
    80000dc2:	c915                	beqz	a0,80000df6 <map_page+0x50>
    if (*pte & PTE_V) return -2; // 冲突
    80000dc4:	611c                	ld	a5,0(a0)
    80000dc6:	8b85                	and	a5,a5,1
    80000dc8:	eb8d                	bnez	a5,80000dfa <map_page+0x54>
    *pte = PA2PTE(pa) | perm | PTE_V | PTE_A | ((perm & PTE_W) ? PTE_D : 0);
    80000dca:	00c4d793          	srl	a5,s1,0xc
    80000dce:	07aa                	sll	a5,a5,0xa
    80000dd0:	0127e7b3          	or	a5,a5,s2
    80000dd4:	0916                	sll	s2,s2,0x5
    80000dd6:	08097913          	and	s2,s2,128
    80000dda:	0127e7b3          	or	a5,a5,s2
    80000dde:	0417e793          	or	a5,a5,65
    80000de2:	e11c                	sd	a5,0(a0)
    return 0;
    80000de4:	4501                	li	a0,0
}
    80000de6:	60e2                	ld	ra,24(sp)
    80000de8:	6442                	ld	s0,16(sp)
    80000dea:	64a2                	ld	s1,8(sp)
    80000dec:	6902                	ld	s2,0(sp)
    80000dee:	6105                	add	sp,sp,32
    80000df0:	8082                	ret
    if (!is_page_aligned(va) || !is_page_aligned(pa)) return -1;
    80000df2:	557d                	li	a0,-1
}
    80000df4:	8082                	ret
    if (!pte) return -1;
    80000df6:	557d                	li	a0,-1
    80000df8:	b7fd                	j	80000de6 <map_page+0x40>
    if (*pte & PTE_V) return -2; // 冲突
    80000dfa:	5579                	li	a0,-2
    80000dfc:	b7ed                	j	80000de6 <map_page+0x40>

0000000080000dfe <kvminit>:
        if (a == last) break;
    }
}
#define PLIC_BASE 0x0c000000ul
#define CLINT_BASE 0x2000000ul
void kvminit(void) {
    80000dfe:	7179                	add	sp,sp,-48
    80000e00:	f406                	sd	ra,40(sp)
    80000e02:	f022                	sd	s0,32(sp)
    80000e04:	ec26                	sd	s1,24(sp)
    80000e06:	e84a                	sd	s2,16(sp)
    80000e08:	e44e                	sd	s3,8(sp)
    80000e0a:	e052                	sd	s4,0(sp)
    80000e0c:	1800                	add	s0,sp,48
    kernel_pagetable = create_pagetable();
    80000e0e:	f4dff0ef          	jal	80000d5a <create_pagetable>
    80000e12:	00006497          	auipc	s1,0x6
    80000e16:	88e48493          	add	s1,s1,-1906 # 800066a0 <kernel_pagetable>
    80000e1a:	e088                	sd	a0,0(s1)
        map_page(pt, a, pa, perm);
    80000e1c:	4699                	li	a3,6
    80000e1e:	0c000637          	lui	a2,0xc000
    80000e22:	0c0005b7          	lui	a1,0xc000
    80000e26:	f81ff0ef          	jal	80000da6 <map_page>
    80000e2a:	4699                	li	a3,6
    80000e2c:	02000637          	lui	a2,0x2000
    80000e30:	020005b7          	lui	a1,0x2000
    80000e34:	6088                	ld	a0,0(s1)
    80000e36:	f71ff0ef          	jal	80000da6 <map_page>
    80000e3a:	4699                	li	a3,6
    80000e3c:	10000637          	lui	a2,0x10000
    80000e40:	100005b7          	lui	a1,0x10000
    80000e44:	6088                	ld	a0,0(s1)
    80000e46:	f61ff0ef          	jal	80000da6 <map_page>
    kvmmap_range(kernel_pagetable, PLIC_BASE, PLIC_BASE, PGSIZE, PTE_R|PTE_W);
    kvmmap_range(kernel_pagetable, CLINT_BASE, CLINT_BASE, PGSIZE, PTE_R|PTE_W);
    kvmmap_range(kernel_pagetable, UART0, UART0, PGSIZE, PTE_R|PTE_W);
    kvmmap_range(kernel_pagetable, MEM_START, MEM_START, MEM_END - MEM_START, PTE_R | PTE_W|PTE_X);
    80000e4a:	0004b983          	ld	s3,0(s1)
    uint64 a = PGROUNDDOWN(va);
    80000e4e:	4485                	li	s1,1
    80000e50:	04fe                	sll	s1,s1,0x1f
        if (a == last) break;
    80000e52:	00088937          	lui	s2,0x88
    80000e56:	197d                	add	s2,s2,-1 # 87fff <_entry-0x7ff78001>
    80000e58:	0932                	sll	s2,s2,0xc
    for (;; a += PGSIZE, pa += PGSIZE) {
    80000e5a:	6a05                	lui	s4,0x1
    80000e5c:	a011                	j	80000e60 <kvminit+0x62>
    80000e5e:	94d2                	add	s1,s1,s4
        map_page(pt, a, pa, perm);
    80000e60:	46b9                	li	a3,14
    80000e62:	8626                	mv	a2,s1
    80000e64:	85a6                	mv	a1,s1
    80000e66:	854e                	mv	a0,s3
    80000e68:	f3fff0ef          	jal	80000da6 <map_page>
        if (a == last) break;
    80000e6c:	ff2499e3          	bne	s1,s2,80000e5e <kvminit+0x60>

    // 映射trampoline到内核高地址空间，供forkret/usertrap返回路径使用
    if(map_page(kernel_pagetable, TRAMPOLINE, (uint64)trampoline, PTE_R | PTE_X)!=0){
    80000e70:	46a9                	li	a3,10
    80000e72:	00017617          	auipc	a2,0x17
    80000e76:	18e60613          	add	a2,a2,398 # 80018000 <trampoline>
    80000e7a:	040005b7          	lui	a1,0x4000
    80000e7e:	15fd                	add	a1,a1,-1 # 3ffffff <_entry-0x7c000001>
    80000e80:	05b2                	sll	a1,a1,0xc
    80000e82:	00006517          	auipc	a0,0x6
    80000e86:	81e53503          	ld	a0,-2018(a0) # 800066a0 <kernel_pagetable>
    80000e8a:	f1dff0ef          	jal	80000da6 <map_page>
    80000e8e:	ed19                	bnez	a0,80000eac <kvminit+0xae>
        panic("Failed to map trampoline");
    };
    
    // 映射所有进程的内核栈
    proc_mapstacks(kernel_pagetable);
    80000e90:	00006517          	auipc	a0,0x6
    80000e94:	81053503          	ld	a0,-2032(a0) # 800066a0 <kernel_pagetable>
    80000e98:	2ec010ef          	jal	80002184 <proc_mapstacks>
}
    80000e9c:	70a2                	ld	ra,40(sp)
    80000e9e:	7402                	ld	s0,32(sp)
    80000ea0:	64e2                	ld	s1,24(sp)
    80000ea2:	6942                	ld	s2,16(sp)
    80000ea4:	69a2                	ld	s3,8(sp)
    80000ea6:	6a02                	ld	s4,0(sp)
    80000ea8:	6145                	add	sp,sp,48
    80000eaa:	8082                	ret
        panic("Failed to map trampoline");
    80000eac:	00005517          	auipc	a0,0x5
    80000eb0:	88450513          	add	a0,a0,-1916 # 80005730 <kalloc+0x172>
    80000eb4:	aedff0ef          	jal	800009a0 <panic>
    80000eb8:	bfe1                	j	80000e90 <kvminit+0x92>

0000000080000eba <kvminithart>:

void kvminithart(void) {
    80000eba:	1141                	add	sp,sp,-16
    80000ebc:	e422                	sd	s0,8(sp)
    80000ebe:	0800                	add	s0,sp,16
    uint64 satp = MAKE_SATP(kernel_pagetable);
    80000ec0:	00005797          	auipc	a5,0x5
    80000ec4:	7e07b783          	ld	a5,2016(a5) # 800066a0 <kernel_pagetable>
    80000ec8:	83b1                	srl	a5,a5,0xc
    80000eca:	577d                	li	a4,-1
    80000ecc:	177e                	sll	a4,a4,0x3f
    80000ece:	8fd9                	or	a5,a5,a4
// supervisor address translation and protection;
// holds the address of the page table.
static inline void 
w_satp(uint64 x)
{
  asm volatile("csrw satp, %0" : : "r" (x));
    80000ed0:	18079073          	csrw	satp,a5
    asm volatile("sfence.vma zero, zero");
    80000ed4:	12000073          	sfence.vma
    // 设置satp寄存器
    w_satp(satp);
    sfence_vma();
}
    80000ed8:	6422                	ld	s0,8(sp)
    80000eda:	0141                	add	sp,sp,16
    80000edc:	8082                	ret

0000000080000ede <uvmunmap>:

// 取消映射用户地址空间中的指定页
// va: 起始虚拟地址（必须是页对齐的）
// npages: 要取消映射的页数
// do_free: 如果为1，释放对应的物理内存；如果为0，只取消映射
void uvmunmap(pagetable_t pagetable, uint64 va, uint64 npages, int do_free) {
    80000ede:	711d                	add	sp,sp,-96
    80000ee0:	ec86                	sd	ra,88(sp)
    80000ee2:	e8a2                	sd	s0,80(sp)
    80000ee4:	e4a6                	sd	s1,72(sp)
    80000ee6:	e0ca                	sd	s2,64(sp)
    80000ee8:	fc4e                	sd	s3,56(sp)
    80000eea:	f852                	sd	s4,48(sp)
    80000eec:	f456                	sd	s5,40(sp)
    80000eee:	f05a                	sd	s6,32(sp)
    80000ef0:	ec5e                	sd	s7,24(sp)
    80000ef2:	e862                	sd	s8,16(sp)
    80000ef4:	e466                	sd	s9,8(sp)
    80000ef6:	1080                	add	s0,sp,96
    80000ef8:	8a2a                	mv	s4,a0
    80000efa:	892e                	mv	s2,a1
    80000efc:	89b2                	mv	s3,a2
    80000efe:	8ab6                	mv	s5,a3
    uint64 a;
    pte_t *pte;

    if ((va % PGSIZE) != 0)
    80000f00:	03459793          	sll	a5,a1,0x34
    80000f04:	e39d                	bnez	a5,80000f2a <uvmunmap+0x4c>
        panic("uvmunmap: not aligned");

    for (a = va; a < va + npages * PGSIZE; a += PGSIZE) {
    80000f06:	09b2                	sll	s3,s3,0xc
    80000f08:	99ca                	add	s3,s3,s2
    80000f0a:	07397c63          	bgeu	s2,s3,80000f82 <uvmunmap+0xa4>
        if ((pte = walk_lookup(pagetable, a)) == 0)
            panic("uvmunmap: walk");
    80000f0e:	00005c97          	auipc	s9,0x5
    80000f12:	85ac8c93          	add	s9,s9,-1958 # 80005768 <kalloc+0x1aa>
        if ((*pte & PTE_V) == 0)
            panic("uvmunmap: not mapped");
    80000f16:	00005c17          	auipc	s8,0x5
    80000f1a:	862c0c13          	add	s8,s8,-1950 # 80005778 <kalloc+0x1ba>
        // 检查是否是叶子页表项（有R/W/X标志位）
        // 如果没有R/W/X标志，说明是指向下一级页表的中间节点，不是叶子
        if ((*pte & (PTE_R | PTE_W | PTE_X)) == 0)
            panic("uvmunmap: not a leaf");
    80000f1e:	00005b97          	auipc	s7,0x5
    80000f22:	872b8b93          	add	s7,s7,-1934 # 80005790 <kalloc+0x1d2>
    for (a = va; a < va + npages * PGSIZE; a += PGSIZE) {
    80000f26:	6b05                	lui	s6,0x1
    80000f28:	a80d                	j	80000f5a <uvmunmap+0x7c>
        panic("uvmunmap: not aligned");
    80000f2a:	00005517          	auipc	a0,0x5
    80000f2e:	82650513          	add	a0,a0,-2010 # 80005750 <kalloc+0x192>
    80000f32:	a6fff0ef          	jal	800009a0 <panic>
    80000f36:	bfc1                	j	80000f06 <uvmunmap+0x28>
            panic("uvmunmap: walk");
    80000f38:	8566                	mv	a0,s9
    80000f3a:	a67ff0ef          	jal	800009a0 <panic>
    80000f3e:	a025                	j	80000f66 <uvmunmap+0x88>
            panic("uvmunmap: not mapped");
    80000f40:	8562                	mv	a0,s8
    80000f42:	a5fff0ef          	jal	800009a0 <panic>
    80000f46:	a01d                	j	80000f6c <uvmunmap+0x8e>
            panic("uvmunmap: not a leaf");
    80000f48:	855e                	mv	a0,s7
    80000f4a:	a57ff0ef          	jal	800009a0 <panic>
    80000f4e:	a015                	j	80000f72 <uvmunmap+0x94>
        if (do_free) {
            uint64 pa = PTE2PA(*pte);
            free_page((void *)pa);
        }
        *pte = 0;
    80000f50:	0004b023          	sd	zero,0(s1)
    for (a = va; a < va + npages * PGSIZE; a += PGSIZE) {
    80000f54:	995a                	add	s2,s2,s6
    80000f56:	03397663          	bgeu	s2,s3,80000f82 <uvmunmap+0xa4>
        if ((pte = walk_lookup(pagetable, a)) == 0)
    80000f5a:	85ca                	mv	a1,s2
    80000f5c:	8552                	mv	a0,s4
    80000f5e:	de7ff0ef          	jal	80000d44 <walk_lookup>
    80000f62:	84aa                	mv	s1,a0
    80000f64:	d971                	beqz	a0,80000f38 <uvmunmap+0x5a>
        if ((*pte & PTE_V) == 0)
    80000f66:	609c                	ld	a5,0(s1)
    80000f68:	8b85                	and	a5,a5,1
    80000f6a:	dbf9                	beqz	a5,80000f40 <uvmunmap+0x62>
        if ((*pte & (PTE_R | PTE_W | PTE_X)) == 0)
    80000f6c:	609c                	ld	a5,0(s1)
    80000f6e:	8bb9                	and	a5,a5,14
    80000f70:	dfe1                	beqz	a5,80000f48 <uvmunmap+0x6a>
        if (do_free) {
    80000f72:	fc0a8fe3          	beqz	s5,80000f50 <uvmunmap+0x72>
            uint64 pa = PTE2PA(*pte);
    80000f76:	6088                	ld	a0,0(s1)
    80000f78:	8129                	srl	a0,a0,0xa
            free_page((void *)pa);
    80000f7a:	0532                	sll	a0,a0,0xc
    80000f7c:	b8fff0ef          	jal	80000b0a <free_page>
    80000f80:	bfc1                	j	80000f50 <uvmunmap+0x72>
    }
}
    80000f82:	60e6                	ld	ra,88(sp)
    80000f84:	6446                	ld	s0,80(sp)
    80000f86:	64a6                	ld	s1,72(sp)
    80000f88:	6906                	ld	s2,64(sp)
    80000f8a:	79e2                	ld	s3,56(sp)
    80000f8c:	7a42                	ld	s4,48(sp)
    80000f8e:	7aa2                	ld	s5,40(sp)
    80000f90:	7b02                	ld	s6,32(sp)
    80000f92:	6be2                	ld	s7,24(sp)
    80000f94:	6c42                	ld	s8,16(sp)
    80000f96:	6ca2                	ld	s9,8(sp)
    80000f98:	6125                	add	sp,sp,96
    80000f9a:	8082                	ret

0000000080000f9c <uvmalloc>:
    if(newsz < oldsz)
    80000f9c:	08b66d63          	bltu	a2,a1,80001036 <uvmalloc+0x9a>
{
    80000fa0:	715d                	add	sp,sp,-80
    80000fa2:	e486                	sd	ra,72(sp)
    80000fa4:	e0a2                	sd	s0,64(sp)
    80000fa6:	fc26                	sd	s1,56(sp)
    80000fa8:	f84a                	sd	s2,48(sp)
    80000faa:	f44e                	sd	s3,40(sp)
    80000fac:	f052                	sd	s4,32(sp)
    80000fae:	ec56                	sd	s5,24(sp)
    80000fb0:	e85a                	sd	s6,16(sp)
    80000fb2:	e45e                	sd	s7,8(sp)
    80000fb4:	0880                	add	s0,sp,80
    80000fb6:	8a2a                	mv	s4,a0
    80000fb8:	8ab2                	mv	s5,a2
    uint64 start = PGROUNDUP(oldsz);
    80000fba:	6985                	lui	s3,0x1
    80000fbc:	19fd                	add	s3,s3,-1 # fff <_entry-0x7ffff001>
    80000fbe:	95ce                	add	a1,a1,s3
    80000fc0:	77fd                	lui	a5,0xfffff
    80000fc2:	00f5fb33          	and	s6,a1,a5
    uint64 end = PGROUNDUP(newsz);
    80000fc6:	99b2                	add	s3,s3,a2
    80000fc8:	00f9f9b3          	and	s3,s3,a5
    int flags = perm | PTE_R | PTE_U;
    80000fcc:	0126eb93          	or	s7,a3,18
    for(a = start; a < end; a += PGSIZE){
    80000fd0:	073b7563          	bgeu	s6,s3,8000103a <uvmalloc+0x9e>
    80000fd4:	895a                	mv	s2,s6
        void *mem = alloc_page();
    80000fd6:	b21ff0ef          	jal	80000af6 <alloc_page>
    80000fda:	84aa                	mv	s1,a0
        if(mem == 0)
    80000fdc:	c50d                	beqz	a0,80001006 <uvmalloc+0x6a>
        memset(mem, 0, PGSIZE);
    80000fde:	6605                	lui	a2,0x1
    80000fe0:	4581                	li	a1,0
    80000fe2:	358040ef          	jal	8000533a <memset>
        if(map_page(pagetable, a, (uint64)mem, flags) != 0){
    80000fe6:	86de                	mv	a3,s7
    80000fe8:	8626                	mv	a2,s1
    80000fea:	85ca                	mv	a1,s2
    80000fec:	8552                	mv	a0,s4
    80000fee:	db9ff0ef          	jal	80000da6 <map_page>
    80000ff2:	e519                	bnez	a0,80001000 <uvmalloc+0x64>
    for(a = start; a < end; a += PGSIZE){
    80000ff4:	6785                	lui	a5,0x1
    80000ff6:	993e                	add	s2,s2,a5
    80000ff8:	fd396fe3          	bltu	s2,s3,80000fd6 <uvmalloc+0x3a>
    return newsz;
    80000ffc:	8556                	mv	a0,s5
    80000ffe:	a039                	j	8000100c <uvmalloc+0x70>
            free_page(mem);
    80001000:	8526                	mv	a0,s1
    80001002:	b09ff0ef          	jal	80000b0a <free_page>
    return 0;
    80001006:	4501                	li	a0,0
    if(a > start)
    80001008:	012b6d63          	bltu	s6,s2,80001022 <uvmalloc+0x86>
}
    8000100c:	60a6                	ld	ra,72(sp)
    8000100e:	6406                	ld	s0,64(sp)
    80001010:	74e2                	ld	s1,56(sp)
    80001012:	7942                	ld	s2,48(sp)
    80001014:	79a2                	ld	s3,40(sp)
    80001016:	7a02                	ld	s4,32(sp)
    80001018:	6ae2                	ld	s5,24(sp)
    8000101a:	6b42                	ld	s6,16(sp)
    8000101c:	6ba2                	ld	s7,8(sp)
    8000101e:	6161                	add	sp,sp,80
    80001020:	8082                	ret
        uvmunmap(pagetable, start, (a - start) / PGSIZE, 1);
    80001022:	41690633          	sub	a2,s2,s6
    80001026:	4685                	li	a3,1
    80001028:	8231                	srl	a2,a2,0xc
    8000102a:	85da                	mv	a1,s6
    8000102c:	8552                	mv	a0,s4
    8000102e:	eb1ff0ef          	jal	80000ede <uvmunmap>
    return 0;
    80001032:	4501                	li	a0,0
    80001034:	bfe1                	j	8000100c <uvmalloc+0x70>
        return oldsz;
    80001036:	852e                	mv	a0,a1
}
    80001038:	8082                	ret
    return newsz;
    8000103a:	8532                	mv	a0,a2
    8000103c:	bfc1                	j	8000100c <uvmalloc+0x70>

000000008000103e <uvmclear>:

void
uvmclear(pagetable_t pagetable, uint64 va)
{
    8000103e:	1101                	add	sp,sp,-32
    80001040:	ec06                	sd	ra,24(sp)
    80001042:	e822                	sd	s0,16(sp)
    80001044:	e426                	sd	s1,8(sp)
    80001046:	1000                	add	s0,sp,32
    pte_t *pte = walk_lookup(pagetable, va);
    80001048:	cfdff0ef          	jal	80000d44 <walk_lookup>
    8000104c:	84aa                	mv	s1,a0
    if(pte == 0)
    8000104e:	c909                	beqz	a0,80001060 <uvmclear+0x22>
        panic("uvmclear: walk");
    *pte &= ~PTE_U;
    80001050:	609c                	ld	a5,0(s1)
    80001052:	9bbd                	and	a5,a5,-17
    80001054:	e09c                	sd	a5,0(s1)
}
    80001056:	60e2                	ld	ra,24(sp)
    80001058:	6442                	ld	s0,16(sp)
    8000105a:	64a2                	ld	s1,8(sp)
    8000105c:	6105                	add	sp,sp,32
    8000105e:	8082                	ret
        panic("uvmclear: walk");
    80001060:	00004517          	auipc	a0,0x4
    80001064:	74850513          	add	a0,a0,1864 # 800057a8 <kalloc+0x1ea>
    80001068:	939ff0ef          	jal	800009a0 <panic>
    8000106c:	b7d5                	j	80001050 <uvmclear+0x12>

000000008000106e <uvmfree>:

// 释放用户地址空间的所有物理内存和页表
// pagetable: 用户页表
// sz: 用户地址空间大小（字节）
void uvmfree(pagetable_t pagetable, uint64 sz) {
    8000106e:	1101                	add	sp,sp,-32
    80001070:	ec06                	sd	ra,24(sp)
    80001072:	e822                	sd	s0,16(sp)
    80001074:	e426                	sd	s1,8(sp)
    80001076:	1000                	add	s0,sp,32
    80001078:	84aa                	mv	s1,a0
    if (sz > 0) {
    8000107a:	e989                	bnez	a1,8000108c <uvmfree+0x1e>
        uvmunmap(pagetable, 0, PGROUNDUP(sz) / PGSIZE, 1);
    }
    destroy_pagetable(pagetable);
    8000107c:	8526                	mv	a0,s1
    8000107e:	d03ff0ef          	jal	80000d80 <destroy_pagetable>
}
    80001082:	60e2                	ld	ra,24(sp)
    80001084:	6442                	ld	s0,16(sp)
    80001086:	64a2                	ld	s1,8(sp)
    80001088:	6105                	add	sp,sp,32
    8000108a:	8082                	ret
        uvmunmap(pagetable, 0, PGROUNDUP(sz) / PGSIZE, 1);
    8000108c:	6785                	lui	a5,0x1
    8000108e:	17fd                	add	a5,a5,-1 # fff <_entry-0x7ffff001>
    80001090:	95be                	add	a1,a1,a5
    80001092:	4685                	li	a3,1
    80001094:	00c5d613          	srl	a2,a1,0xc
    80001098:	4581                	li	a1,0
    8000109a:	e45ff0ef          	jal	80000ede <uvmunmap>
    8000109e:	bff9                	j	8000107c <uvmfree+0xe>

00000000800010a0 <vmfault>:
// that was lazily allocated in sys_sbrk().
// returns 0 if va is invalid or already mapped, or if
// out of physical memory, and physical address if successful.
uint64
vmfault(pagetable_t pagetable, uint64 va, int read)
{
    800010a0:	7179                	add	sp,sp,-48
    800010a2:	f406                	sd	ra,40(sp)
    800010a4:	f022                	sd	s0,32(sp)
    800010a6:	ec26                	sd	s1,24(sp)
    800010a8:	e84a                	sd	s2,16(sp)
    800010aa:	e44e                	sd	s3,8(sp)
    800010ac:	e052                	sd	s4,0(sp)
    800010ae:	1800                	add	s0,sp,48
    800010b0:	89aa                	mv	s3,a0
    800010b2:	84ae                	mv	s1,a1
    uint64 mem;
    struct proc *p = myproc();
    800010b4:	4ae010ef          	jal	80002562 <myproc>
    pte_t *pte;

    if (va >= p->sz)
    800010b8:	617c                	ld	a5,192(a0)
    800010ba:	00f4ec63          	bltu	s1,a5,800010d2 <vmfault+0x32>
        return 0;
    800010be:	4981                	li	s3,0
        free_page((void *)mem);
        return 0;
    }

    return mem;
}
    800010c0:	854e                	mv	a0,s3
    800010c2:	70a2                	ld	ra,40(sp)
    800010c4:	7402                	ld	s0,32(sp)
    800010c6:	64e2                	ld	s1,24(sp)
    800010c8:	6942                	ld	s2,16(sp)
    800010ca:	69a2                	ld	s3,8(sp)
    800010cc:	6a02                	ld	s4,0(sp)
    800010ce:	6145                	add	sp,sp,48
    800010d0:	8082                	ret
    800010d2:	892a                	mv	s2,a0
    va = PGROUNDDOWN(va);
    800010d4:	77fd                	lui	a5,0xfffff
    800010d6:	8cfd                	and	s1,s1,a5
    pte = walk_lookup(pagetable, va);
    800010d8:	85a6                	mv	a1,s1
    800010da:	854e                	mv	a0,s3
    800010dc:	c69ff0ef          	jal	80000d44 <walk_lookup>
    if (pte && (*pte & PTE_V)) {
    800010e0:	c509                	beqz	a0,800010ea <vmfault+0x4a>
    800010e2:	611c                	ld	a5,0(a0)
    800010e4:	8b85                	and	a5,a5,1
        return 0;  // 已经映射
    800010e6:	4981                	li	s3,0
    if (pte && (*pte & PTE_V)) {
    800010e8:	ffe1                	bnez	a5,800010c0 <vmfault+0x20>
    mem = (uint64) alloc_page();
    800010ea:	a0dff0ef          	jal	80000af6 <alloc_page>
    800010ee:	8a2a                	mv	s4,a0
        return 0;
    800010f0:	4981                	li	s3,0
    if (mem == 0)
    800010f2:	d579                	beqz	a0,800010c0 <vmfault+0x20>
    mem = (uint64) alloc_page();
    800010f4:	89aa                	mv	s3,a0
    memset((void *) mem, 0, PGSIZE);
    800010f6:	6605                	lui	a2,0x1
    800010f8:	4581                	li	a1,0
    800010fa:	240040ef          	jal	8000533a <memset>
    if (map_page(p->pagetable, va, mem, PTE_W | PTE_U | PTE_R) != 0) {
    800010fe:	46d9                	li	a3,22
    80001100:	8652                	mv	a2,s4
    80001102:	85a6                	mv	a1,s1
    80001104:	0c893503          	ld	a0,200(s2)
    80001108:	c9fff0ef          	jal	80000da6 <map_page>
    8000110c:	d955                	beqz	a0,800010c0 <vmfault+0x20>
        free_page((void *)mem);
    8000110e:	8552                	mv	a0,s4
    80001110:	9fbff0ef          	jal	80000b0a <free_page>
        return 0;
    80001114:	4981                	li	s3,0
    80001116:	b76d                	j	800010c0 <vmfault+0x20>

0000000080001118 <uvmdealloc>:

// 释放用户内存，返回新的大小
uint64
uvmdealloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
{
    80001118:	1101                	add	sp,sp,-32
    8000111a:	ec06                	sd	ra,24(sp)
    8000111c:	e822                	sd	s0,16(sp)
    8000111e:	e426                	sd	s1,8(sp)
    80001120:	1000                	add	s0,sp,32
  if(newsz >= oldsz)
    return oldsz;
    80001122:	84ae                	mv	s1,a1
  if(newsz >= oldsz)
    80001124:	00b67d63          	bgeu	a2,a1,8000113e <uvmdealloc+0x26>
    80001128:	84b2                	mv	s1,a2

  if(PGROUNDUP(newsz) < PGROUNDUP(oldsz)){
    8000112a:	6785                	lui	a5,0x1
    8000112c:	17fd                	add	a5,a5,-1 # fff <_entry-0x7ffff001>
    8000112e:	00f60733          	add	a4,a2,a5
    80001132:	76fd                	lui	a3,0xfffff
    80001134:	8f75                	and	a4,a4,a3
    80001136:	97ae                	add	a5,a5,a1
    80001138:	8ff5                	and	a5,a5,a3
    8000113a:	00f76863          	bltu	a4,a5,8000114a <uvmdealloc+0x32>
    int npages = (PGROUNDUP(oldsz) - PGROUNDUP(newsz)) / PGSIZE;
    uvmunmap(pagetable, PGROUNDUP(newsz), npages, 1);
  }

  return newsz;
}
    8000113e:	8526                	mv	a0,s1
    80001140:	60e2                	ld	ra,24(sp)
    80001142:	6442                	ld	s0,16(sp)
    80001144:	64a2                	ld	s1,8(sp)
    80001146:	6105                	add	sp,sp,32
    80001148:	8082                	ret
    int npages = (PGROUNDUP(oldsz) - PGROUNDUP(newsz)) / PGSIZE;
    8000114a:	8f99                	sub	a5,a5,a4
    8000114c:	83b1                	srl	a5,a5,0xc
    uvmunmap(pagetable, PGROUNDUP(newsz), npages, 1);
    8000114e:	4685                	li	a3,1
    80001150:	0007861b          	sext.w	a2,a5
    80001154:	85ba                	mv	a1,a4
    80001156:	d89ff0ef          	jal	80000ede <uvmunmap>
    8000115a:	b7d5                	j	8000113e <uvmdealloc+0x26>
    8000115c:	0000                	unimp
	...

0000000080001160 <kernelvec>:
.section .text
.globl kernelvec
.align 4
kernelvec:
    # make room to save registers.
        addi sp, sp, -256
    80001160:	7111                	add	sp,sp,-256

        # save caller-saved registers.
        sd ra, 0(sp)
    80001162:	e006                	sd	ra,0(sp)
        # sd sp, 8(sp)
        sd gp, 16(sp)
    80001164:	e80e                	sd	gp,16(sp)
        sd tp, 24(sp)
    80001166:	ec12                	sd	tp,24(sp)
        sd t0, 32(sp)
    80001168:	f016                	sd	t0,32(sp)
        sd t1, 40(sp)
    8000116a:	f41a                	sd	t1,40(sp)
        sd t2, 48(sp)
    8000116c:	f81e                	sd	t2,48(sp)
        sd a0, 72(sp)
    8000116e:	e4aa                	sd	a0,72(sp)
        sd a1, 80(sp)
    80001170:	e8ae                	sd	a1,80(sp)
        sd a2, 88(sp)
    80001172:	ecb2                	sd	a2,88(sp)
        sd a3, 96(sp)
    80001174:	f0b6                	sd	a3,96(sp)
        sd a4, 104(sp)
    80001176:	f4ba                	sd	a4,104(sp)
        sd a5, 112(sp)
    80001178:	f8be                	sd	a5,112(sp)
        sd a6, 120(sp)
    8000117a:	fcc2                	sd	a6,120(sp)
        sd a7, 128(sp)
    8000117c:	e146                	sd	a7,128(sp)
        sd t3, 216(sp)
    8000117e:	edf2                	sd	t3,216(sp)
        sd t4, 224(sp)
    80001180:	f1f6                	sd	t4,224(sp)
        sd t5, 232(sp)
    80001182:	f5fa                	sd	t5,232(sp)
        sd t6, 240(sp)
    80001184:	f9fe                	sd	t6,240(sp)

        # call the C trap handler in trap.c
        call kerneltrap
    80001186:	506000ef          	jal	8000168c <kerneltrap>

        # restore registers.
        ld ra, 0(sp)
    8000118a:	6082                	ld	ra,0(sp)
        # ld sp, 8(sp)
        ld gp, 16(sp)
    8000118c:	61c2                	ld	gp,16(sp)
        # not tp (contains hartid), in case we moved CPUs
        ld t0, 32(sp)
    8000118e:	7282                	ld	t0,32(sp)
        ld t1, 40(sp)
    80001190:	7322                	ld	t1,40(sp)
        ld t2, 48(sp)
    80001192:	73c2                	ld	t2,48(sp)
        ld a0, 72(sp)
    80001194:	6526                	ld	a0,72(sp)
        ld a1, 80(sp)
    80001196:	65c6                	ld	a1,80(sp)
        ld a2, 88(sp)
    80001198:	6666                	ld	a2,88(sp)
        ld a3, 96(sp)
    8000119a:	7686                	ld	a3,96(sp)
        ld a4, 104(sp)
    8000119c:	7726                	ld	a4,104(sp)
        ld a5, 112(sp)
    8000119e:	77c6                	ld	a5,112(sp)
        ld a6, 120(sp)
    800011a0:	7866                	ld	a6,120(sp)
        ld a7, 128(sp)
    800011a2:	688a                	ld	a7,128(sp)
        ld t3, 216(sp)
    800011a4:	6e6e                	ld	t3,216(sp)
        ld t4, 224(sp)
    800011a6:	7e8e                	ld	t4,224(sp)
        ld t5, 232(sp)
    800011a8:	7f2e                	ld	t5,232(sp)
        ld t6, 240(sp)
    800011aa:	7fce                	ld	t6,240(sp)

        addi sp, sp, 256
    800011ac:	6111                	add	sp,sp,256

        # return to whatever we were doing in the kernel.
    800011ae:	10200073          	sret
	...

00000000800011be <handle_external>:
    // 这里只是标记时钟中断已经发生
}

// 外部中断处理函数
void handle_external(void) {
    printf("External interrupt occurred\n");
    800011be:	00004517          	auipc	a0,0x4
    800011c2:	5fa50513          	add	a0,a0,1530 # 800057b8 <kalloc+0x1fa>
    800011c6:	9c0ff06f          	j	80000386 <printf>

00000000800011ca <handle_software>:
}

// 软件中断处理函数
void handle_software(void) {
    printf("Software interrupt occurred\n");
    800011ca:	00004517          	auipc	a0,0x4
    800011ce:	60e50513          	add	a0,a0,1550 # 800057d8 <kalloc+0x21a>
    800011d2:	9b4ff06f          	j	80000386 <printf>

00000000800011d6 <handle_timer>:
    ticks++;
    800011d6:	00005717          	auipc	a4,0x5
    800011da:	4da70713          	add	a4,a4,1242 # 800066b0 <ticks>
    800011de:	631c                	ld	a5,0(a4)
    800011e0:	0785                	add	a5,a5,1
    800011e2:	e31c                	sd	a5,0(a4)
    if (test_mode) {
    800011e4:	00005797          	auipc	a5,0x5
    800011e8:	4c47a783          	lw	a5,1220(a5) # 800066a8 <test_mode>
    800011ec:	eb99                	bnez	a5,80001202 <handle_timer+0x2c>
// machine-mode cycle counter
static inline uint64
r_time()
{
  uint64 x;
  asm volatile("csrr %0, time" : "=r" (x) );
    800011ee:	c01027f3          	rdtime	a5
    sbi_set_timer(get_time() + 1000000);
    800011f2:	000f4737          	lui	a4,0xf4
    800011f6:	24070713          	add	a4,a4,576 # f4240 <_entry-0x7ff0bdc0>
    800011fa:	97ba                	add	a5,a5,a4
   asm volatile("csrw 0x14d, %0" : : "r" (x));
    800011fc:	14d79073          	csrw	stimecmp,a5
    80001200:	8082                	ret
void handle_timer(void) {
    80001202:	1141                	add	sp,sp,-16
        test_interrupt_count++;
    80001204:	00005797          	auipc	a5,0x5
    80001208:	4a87a783          	lw	a5,1192(a5) # 800066ac <test_interrupt_count>
void handle_timer(void) {
    8000120c:	e406                	sd	ra,8(sp)
        test_interrupt_count++;
    8000120e:	00005717          	auipc	a4,0x5
    80001212:	49e70713          	add	a4,a4,1182 # 800066ac <test_interrupt_count>
    80001216:	2785                	addw	a5,a5,1
    80001218:	c31c                	sw	a5,0(a4)
        printf("Test timer interrupt %d occurred\n", test_interrupt_count);
    8000121a:	430c                	lw	a1,0(a4)
    8000121c:	00004517          	auipc	a0,0x4
    80001220:	5dc50513          	add	a0,a0,1500 # 800057f8 <kalloc+0x23a>
    80001224:	962ff0ef          	jal	80000386 <printf>
  asm volatile("csrr %0, time" : "=r" (x) );
    80001228:	c01027f3          	rdtime	a5
    sbi_set_timer(get_time() + 1000000);
    8000122c:	000f4737          	lui	a4,0xf4
    80001230:	24070713          	add	a4,a4,576 # f4240 <_entry-0x7ff0bdc0>
    80001234:	97ba                	add	a5,a5,a4
   asm volatile("csrw 0x14d, %0" : : "r" (x));
    80001236:	14d79073          	csrw	stimecmp,a5
}
    8000123a:	60a2                	ld	ra,8(sp)
    8000123c:	0141                	add	sp,sp,16
    8000123e:	8082                	ret

0000000080001240 <trap_init>:
    for (int i = 0; i < MAX_IRQ; i++) {
    80001240:	00005697          	auipc	a3,0x5
    80001244:	4a068693          	add	a3,a3,1184 # 800066e0 <irq_table>
    80001248:	87b6                	mv	a5,a3
    8000124a:	00005717          	auipc	a4,0x5
    8000124e:	51670713          	add	a4,a4,1302 # 80006760 <console_file_wo>
        irq_table[i] = 0;
    80001252:	0007b023          	sd	zero,0(a5)
    for (int i = 0; i < MAX_IRQ; i++) {
    80001256:	07a1                	add	a5,a5,8
    80001258:	fee79de3          	bne	a5,a4,80001252 <trap_init+0x12>
        irq_table[irq] = handler;
    8000125c:	00000797          	auipc	a5,0x0
    80001260:	f7a78793          	add	a5,a5,-134 # 800011d6 <handle_timer>
    80001264:	f69c                	sd	a5,40(a3)
    80001266:	00000797          	auipc	a5,0x0
    8000126a:	f5878793          	add	a5,a5,-168 # 800011be <handle_external>
    8000126e:	e6bc                	sd	a5,72(a3)
    80001270:	00000797          	auipc	a5,0x0
    80001274:	f5a78793          	add	a5,a5,-166 # 800011ca <handle_software>
    80001278:	e69c                	sd	a5,8(a3)
  asm volatile("csrw stvec, %0" : : "r" (x));
    8000127a:	00000797          	auipc	a5,0x0
    8000127e:	ee678793          	add	a5,a5,-282 # 80001160 <kernelvec>
    80001282:	10579073          	csrw	stvec,a5
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80001286:	100027f3          	csrr	a5,sstatus

// enable device interrupts
static inline void
intr_on()
{
  w_sstatus(r_sstatus() | SSTATUS_SIE);
    8000128a:	0027e793          	or	a5,a5,2
  asm volatile("csrw sstatus, %0" : : "r" (x));
    8000128e:	10079073          	csrw	sstatus,a5
    printf("Trap system initialized\n");
    80001292:	00004517          	auipc	a0,0x4
    80001296:	58e50513          	add	a0,a0,1422 # 80005820 <kalloc+0x262>
    8000129a:	8ecff06f          	j	80000386 <printf>

000000008000129e <register_interrupt>:
    if (irq >= 0 && irq < MAX_IRQ) {
    8000129e:	47bd                	li	a5,15
    800012a0:	00a7e963          	bltu	a5,a0,800012b2 <register_interrupt+0x14>
        irq_table[irq] = handler;
    800012a4:	050e                	sll	a0,a0,0x3
    800012a6:	00005797          	auipc	a5,0x5
    800012aa:	43a78793          	add	a5,a5,1082 # 800066e0 <irq_table>
    800012ae:	97aa                	add	a5,a5,a0
    800012b0:	e38c                	sd	a1,0(a5)
}
    800012b2:	8082                	ret

00000000800012b4 <unregister_interrupt>:
    if (irq >= 0 && irq < MAX_IRQ) {
    800012b4:	47bd                	li	a5,15
    800012b6:	00a7f363          	bgeu	a5,a0,800012bc <unregister_interrupt+0x8>
}
    800012ba:	8082                	ret
        irq_table[irq] = 0;
    800012bc:	00351713          	sll	a4,a0,0x3
    800012c0:	00005797          	auipc	a5,0x5
    800012c4:	42078793          	add	a5,a5,1056 # 800066e0 <irq_table>
    800012c8:	97ba                	add	a5,a5,a4
        printf("Unregistered interrupt handler for IRQ %d\n", irq);
    800012ca:	85aa                	mv	a1,a0
    800012cc:	00004517          	auipc	a0,0x4
    800012d0:	57450513          	add	a0,a0,1396 # 80005840 <kalloc+0x282>
        irq_table[irq] = 0;
    800012d4:	0007b023          	sd	zero,0(a5)
        printf("Unregistered interrupt handler for IRQ %d\n", irq);
    800012d8:	8aeff06f          	j	80000386 <printf>

00000000800012dc <enable_interrupt>:
  asm volatile("csrr %0, sie" : "=r" (x) );
    800012dc:	104027f3          	csrr	a5,sie
    switch (irq) {
    800012e0:	4715                	li	a4,5
    800012e2:	00e50c63          	beq	a0,a4,800012fa <enable_interrupt+0x1e>
    800012e6:	4725                	li	a4,9
    800012e8:	00e50e63          	beq	a0,a4,80001304 <enable_interrupt+0x28>
            printf("Cannot enable IRQ %d - not supported\n", irq);
    800012ec:	85aa                	mv	a1,a0
    800012ee:	00004517          	auipc	a0,0x4
    800012f2:	58250513          	add	a0,a0,1410 # 80005870 <kalloc+0x2b2>
    800012f6:	890ff06f          	j	80000386 <printf>
            w_sie(sie | SIE_STIE);
    800012fa:	0207e793          	or	a5,a5,32
  asm volatile("csrw sie, %0" : : "r" (x));
    800012fe:	10479073          	csrw	sie,a5
}
    80001302:	8082                	ret
            w_sie(sie | SIE_SEIE);
    80001304:	2007e793          	or	a5,a5,512
  asm volatile("csrw sie, %0" : : "r" (x));
    80001308:	10479073          	csrw	sie,a5
}
    8000130c:	8082                	ret

000000008000130e <disable_interrupt>:
  asm volatile("csrr %0, sie" : "=r" (x) );
    8000130e:	104027f3          	csrr	a5,sie
    switch (irq) {
    80001312:	4715                	li	a4,5
    80001314:	00e50c63          	beq	a0,a4,8000132c <disable_interrupt+0x1e>
    80001318:	4725                	li	a4,9
    8000131a:	00e50e63          	beq	a0,a4,80001336 <disable_interrupt+0x28>
            printf("Cannot disable IRQ %d - not supported\n", irq);
    8000131e:	85aa                	mv	a1,a0
    80001320:	00004517          	auipc	a0,0x4
    80001324:	57850513          	add	a0,a0,1400 # 80005898 <kalloc+0x2da>
    80001328:	85eff06f          	j	80000386 <printf>
            w_sie(sie & ~SIE_STIE);
    8000132c:	fdf7f793          	and	a5,a5,-33
  asm volatile("csrw sie, %0" : : "r" (x));
    80001330:	10479073          	csrw	sie,a5
}
    80001334:	8082                	ret
            w_sie(sie & ~SIE_SEIE);
    80001336:	dff7f793          	and	a5,a5,-513
  asm volatile("csrw sie, %0" : : "r" (x));
    8000133a:	10479073          	csrw	sie,a5
}
    8000133e:	8082                	ret

0000000080001340 <handle_instruction_page_fault>:
            break;
    }
}

// 指令页故障处理
void handle_instruction_page_fault(uint64 sepc, uint64 stval) {
    80001340:	1101                	add	sp,sp,-32
    80001342:	e822                	sd	s0,16(sp)
    80001344:	e426                	sd	s1,8(sp)
    80001346:	842a                	mv	s0,a0
    80001348:	84ae                	mv	s1,a1
    printf("Instruction page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    8000134a:	862e                	mv	a2,a1
    8000134c:	85aa                	mv	a1,a0
    8000134e:	00004517          	auipc	a0,0x4
    80001352:	57250513          	add	a0,a0,1394 # 800058c0 <kalloc+0x302>
void handle_instruction_page_fault(uint64 sepc, uint64 stval) {
    80001356:	ec06                	sd	ra,24(sp)
    printf("Instruction page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    80001358:	82eff0ef          	jal	80000386 <printf>
    
    // 检查地址是否在有效范围内
    if (stval < 0x80000000 || stval > 0x80000000 + 0x200000) {
    8000135c:	800007b7          	lui	a5,0x80000
    80001360:	94be                	add	s1,s1,a5
    80001362:	002007b7          	lui	a5,0x200
        printf("FATAL: Instruction page fault at invalid address\n");
        // 对于测试，我们跳过导致故障的指令
        w_sepc(sepc + 4);
    80001366:	0411                	add	s0,s0,4
    if (stval < 0x80000000 || stval > 0x80000000 + 0x200000) {
    80001368:	0097ef63          	bltu	a5,s1,80001386 <handle_instruction_page_fault+0x46>
    // 这里应该实现页故障处理逻辑
    // 1. 检查页表项
    // 2. 分配新页面
    // 3. 更新页表
    // 4. 刷新TLB
    printf("Instruction page fault handled - would allocate page\n");
    8000136c:	00004517          	auipc	a0,0x4
    80001370:	5c450513          	add	a0,a0,1476 # 80005930 <kalloc+0x372>
    80001374:	812ff0ef          	jal	80000386 <printf>
  asm volatile("csrw sepc, %0" : : "r" (x));
    80001378:	14141073          	csrw	sepc,s0
    // 跳过导致故障的指令
    w_sepc(sepc + 4);
}
    8000137c:	60e2                	ld	ra,24(sp)
    8000137e:	6442                	ld	s0,16(sp)
    80001380:	64a2                	ld	s1,8(sp)
    80001382:	6105                	add	sp,sp,32
    80001384:	8082                	ret
        printf("FATAL: Instruction page fault at invalid address\n");
    80001386:	00004517          	auipc	a0,0x4
    8000138a:	57250513          	add	a0,a0,1394 # 800058f8 <kalloc+0x33a>
    8000138e:	ff9fe0ef          	jal	80000386 <printf>
    80001392:	14141073          	csrw	sepc,s0
}
    80001396:	60e2                	ld	ra,24(sp)
    80001398:	6442                	ld	s0,16(sp)
    8000139a:	64a2                	ld	s1,8(sp)
    8000139c:	6105                	add	sp,sp,32
    8000139e:	8082                	ret

00000000800013a0 <handle_load_page_fault>:

// 加载页故障处理
void handle_load_page_fault(uint64 sepc, uint64 stval) {
    800013a0:	1141                	add	sp,sp,-16
    800013a2:	e022                	sd	s0,0(sp)
    800013a4:	842e                	mv	s0,a1
    printf("Load page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800013a6:	8622                	mv	a2,s0
void handle_load_page_fault(uint64 sepc, uint64 stval) {
    800013a8:	85aa                	mv	a1,a0
    printf("Load page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800013aa:	00004517          	auipc	a0,0x4
    800013ae:	5be50513          	add	a0,a0,1470 # 80005968 <kalloc+0x3aa>
void handle_load_page_fault(uint64 sepc, uint64 stval) {
    800013b2:	e406                	sd	ra,8(sp)
    printf("Load page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800013b4:	fd3fe0ef          	jal	80000386 <printf>
    
    // 检查地址是否在有效范围内
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    800013b8:	800007b7          	lui	a5,0x80000
    800013bc:	943e                	add	s0,s0,a5
    800013be:	080007b7          	lui	a5,0x8000
        panic("Load page fault at invalid address,exiting...");
        return;
    }
    
    // 页故障处理逻辑
   panic("Load page fault \n");
    800013c2:	00004517          	auipc	a0,0x4
    800013c6:	63650513          	add	a0,a0,1590 # 800059f8 <kalloc+0x43a>
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    800013ca:	0087fc63          	bgeu	a5,s0,800013e2 <handle_load_page_fault+0x42>
        printf("FATAL: Load page fault at invalid address\n");
    800013ce:	00004517          	auipc	a0,0x4
    800013d2:	5ca50513          	add	a0,a0,1482 # 80005998 <kalloc+0x3da>
    800013d6:	fb1fe0ef          	jal	80000386 <printf>
        panic("Load page fault at invalid address,exiting...");
    800013da:	00004517          	auipc	a0,0x4
    800013de:	5ee50513          	add	a0,a0,1518 # 800059c8 <kalloc+0x40a>
}
    800013e2:	6402                	ld	s0,0(sp)
    800013e4:	60a2                	ld	ra,8(sp)
    800013e6:	0141                	add	sp,sp,16
   panic("Load page fault \n");
    800013e8:	db8ff06f          	j	800009a0 <panic>

00000000800013ec <handle_store_page_fault>:

// 存储页故障处理
void handle_store_page_fault(uint64 sepc, uint64 stval) {
    800013ec:	1101                	add	sp,sp,-32
    800013ee:	e822                	sd	s0,16(sp)
    800013f0:	e426                	sd	s1,8(sp)
    800013f2:	842a                	mv	s0,a0
    800013f4:	84ae                	mv	s1,a1
    printf("Store page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800013f6:	862e                	mv	a2,a1
    800013f8:	85aa                	mv	a1,a0
    800013fa:	00004517          	auipc	a0,0x4
    800013fe:	61650513          	add	a0,a0,1558 # 80005a10 <kalloc+0x452>
void handle_store_page_fault(uint64 sepc, uint64 stval) {
    80001402:	ec06                	sd	ra,24(sp)
    printf("Store page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    80001404:	f83fe0ef          	jal	80000386 <printf>
    
    // 检查地址是否在有效范围内
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    80001408:	800007b7          	lui	a5,0x80000
    8000140c:	94be                	add	s1,s1,a5
    8000140e:	080007b7          	lui	a5,0x8000
        printf("FATAL: Store page fault at invalid address\n");
        // 对于测试，我们跳过导致故障的指令
        w_sepc(sepc + 4);
    80001412:	0411                	add	s0,s0,4
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    80001414:	0097ef63          	bltu	a5,s1,80001432 <handle_store_page_fault+0x46>
        return;
    }
    
    // 页故障处理逻辑
    printf("Store page fault handled - would allocate page\n");
    80001418:	00004517          	auipc	a0,0x4
    8000141c:	65850513          	add	a0,a0,1624 # 80005a70 <kalloc+0x4b2>
    80001420:	f67fe0ef          	jal	80000386 <printf>
    80001424:	14141073          	csrw	sepc,s0
    // 跳过导致故障的指令
    w_sepc(sepc + 4);
}
    80001428:	60e2                	ld	ra,24(sp)
    8000142a:	6442                	ld	s0,16(sp)
    8000142c:	64a2                	ld	s1,8(sp)
    8000142e:	6105                	add	sp,sp,32
    80001430:	8082                	ret
        printf("FATAL: Store page fault at invalid address\n");
    80001432:	00004517          	auipc	a0,0x4
    80001436:	60e50513          	add	a0,a0,1550 # 80005a40 <kalloc+0x482>
    8000143a:	f4dfe0ef          	jal	80000386 <printf>
    8000143e:	14141073          	csrw	sepc,s0
}
    80001442:	60e2                	ld	ra,24(sp)
    80001444:	6442                	ld	s0,16(sp)
    80001446:	64a2                	ld	s1,8(sp)
    80001448:	6105                	add	sp,sp,32
    8000144a:	8082                	ret

000000008000144c <handle_illegal_instruction>:

// 非法指令处理
void handle_illegal_instruction(uint64 sepc, uint64 stval) {
    8000144c:	1101                	add	sp,sp,-32
    8000144e:	e822                	sd	s0,16(sp)
    80001450:	e426                	sd	s1,8(sp)
    printf("Illegal instruction at PC=0x%lx, instruction=0x%lx\n", sepc, stval);
    80001452:	862e                	mv	a2,a1
void handle_illegal_instruction(uint64 sepc, uint64 stval) {
    80001454:	84aa                	mv	s1,a0
    80001456:	842e                	mv	s0,a1
    printf("Illegal instruction at PC=0x%lx, instruction=0x%lx\n", sepc, stval);
    80001458:	85aa                	mv	a1,a0
    8000145a:	00004517          	auipc	a0,0x4
    8000145e:	64650513          	add	a0,a0,1606 # 80005aa0 <kalloc+0x4e2>
void handle_illegal_instruction(uint64 sepc, uint64 stval) {
    80001462:	ec06                	sd	ra,24(sp)
    printf("Illegal instruction at PC=0x%lx, instruction=0x%lx\n", sepc, stval);
    80001464:	f23fe0ef          	jal	80000386 <printf>
    
    // 分析非法指令
    uint32 instruction = (uint32)stval;
    printf("Illegal instruction details:\n");
    80001468:	00004517          	auipc	a0,0x4
    8000146c:	67050513          	add	a0,a0,1648 # 80005ad8 <kalloc+0x51a>
    uint32 instruction = (uint32)stval;
    80001470:	2401                	sext.w	s0,s0
    printf("Illegal instruction details:\n");
    80001472:	f15fe0ef          	jal	80000386 <printf>
    printf("  Opcode: 0x%02x\n", instruction & 0x7F);
    80001476:	07f47593          	and	a1,s0,127
    8000147a:	00004517          	auipc	a0,0x4
    8000147e:	67e50513          	add	a0,a0,1662 # 80005af8 <kalloc+0x53a>
    80001482:	f05fe0ef          	jal	80000386 <printf>
    printf("  Function3: 0x%x\n", (instruction >> 12) & 0x7);
    80001486:	00c4559b          	srlw	a1,s0,0xc
    8000148a:	899d                	and	a1,a1,7
    8000148c:	00004517          	auipc	a0,0x4
    80001490:	68450513          	add	a0,a0,1668 # 80005b10 <kalloc+0x552>
    80001494:	ef3fe0ef          	jal	80000386 <printf>
    printf("  Function7: 0x%02x\n", (instruction >> 25) & 0x7F);
    80001498:	0194559b          	srlw	a1,s0,0x19
    8000149c:	00004517          	auipc	a0,0x4
    800014a0:	68c50513          	add	a0,a0,1676 # 80005b28 <kalloc+0x56a>
    800014a4:	ee3fe0ef          	jal	80000386 <printf>
    
    // 跳过导致异常的指令，避免无限循环
    w_sepc(sepc + 4);  // RISC-V指令长度为4字节
    800014a8:	0491                	add	s1,s1,4
    800014aa:	14149073          	csrw	sepc,s1
    
    printf("Illegal instruction handled, skipping to next instruction\n");
}
    800014ae:	6442                	ld	s0,16(sp)
    800014b0:	60e2                	ld	ra,24(sp)
    800014b2:	64a2                	ld	s1,8(sp)
    printf("Illegal instruction handled, skipping to next instruction\n");
    800014b4:	00004517          	auipc	a0,0x4
    800014b8:	68c50513          	add	a0,a0,1676 # 80005b40 <kalloc+0x582>
}
    800014bc:	6105                	add	sp,sp,32
    printf("Illegal instruction handled, skipping to next instruction\n");
    800014be:	ec9fe06f          	j	80000386 <printf>

00000000800014c2 <handle_exception>:
void handle_exception(uint64 scause, uint64 sepc, uint64 stval) {
    800014c2:	1101                	add	sp,sp,-32
    800014c4:	e822                	sd	s0,16(sp)
    800014c6:	ec06                	sd	ra,24(sp)
    switch (scause) {
    800014c8:	47bd                	li	a5,15
void handle_exception(uint64 scause, uint64 sepc, uint64 stval) {
    800014ca:	842e                	mv	s0,a1
    switch (scause) {
    800014cc:	00a7ec63          	bltu	a5,a0,800014e4 <handle_exception+0x22>
    800014d0:	00005717          	auipc	a4,0x5
    800014d4:	a1c70713          	add	a4,a4,-1508 # 80005eec <kalloc+0x92e>
    800014d8:	00251793          	sll	a5,a0,0x2
    800014dc:	97ba                	add	a5,a5,a4
    800014de:	439c                	lw	a5,0(a5)
    800014e0:	97ba                	add	a5,a5,a4
    800014e2:	8782                	jr	a5
            printf("Unhandled exception: cause=%d, sepc=0x%lx, stval=0x%lx\n", 
    800014e4:	86b2                	mv	a3,a2
    800014e6:	8622                	mv	a2,s0
}
    800014e8:	6442                	ld	s0,16(sp)
    800014ea:	60e2                	ld	ra,24(sp)
            printf("Unhandled exception: cause=%d, sepc=0x%lx, stval=0x%lx\n", 
    800014ec:	85aa                	mv	a1,a0
    800014ee:	00005517          	auipc	a0,0x5
    800014f2:	8fa50513          	add	a0,a0,-1798 # 80005de8 <kalloc+0x82a>
}
    800014f6:	6105                	add	sp,sp,32
            printf("Unhandled exception: cause=%d, sepc=0x%lx, stval=0x%lx\n", 
    800014f8:	e8ffe06f          	j	80000386 <printf>
            printf("Instruction address misaligned at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800014fc:	00004517          	auipc	a0,0x4
    80001500:	78c50513          	add	a0,a0,1932 # 80005c88 <kalloc+0x6ca>
}
    80001504:	6442                	ld	s0,16(sp)
    80001506:	60e2                	ld	ra,24(sp)
    80001508:	6105                	add	sp,sp,32
            printf("Store access fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    8000150a:	e7dfe06f          	j	80000386 <printf>
            printf("Instruction access fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    8000150e:	00004517          	auipc	a0,0x4
    80001512:	7ba50513          	add	a0,a0,1978 # 80005cc8 <kalloc+0x70a>
    80001516:	b7fd                	j	80001504 <handle_exception+0x42>
            handle_illegal_instruction(sepc, stval);
    80001518:	8522                	mv	a0,s0
}
    8000151a:	6442                	ld	s0,16(sp)
    8000151c:	60e2                	ld	ra,24(sp)
            handle_illegal_instruction(sepc, stval);
    8000151e:	85b2                	mv	a1,a2
}
    80001520:	6105                	add	sp,sp,32
            handle_illegal_instruction(sepc, stval);
    80001522:	b72d                	j	8000144c <handle_illegal_instruction>
}
    80001524:	6442                	ld	s0,16(sp)
    80001526:	60e2                	ld	ra,24(sp)
            printf("Breakpoint at PC=0x%lx\n", sepc);
    80001528:	00004517          	auipc	a0,0x4
    8000152c:	7d850513          	add	a0,a0,2008 # 80005d00 <kalloc+0x742>
}
    80001530:	6105                	add	sp,sp,32
            printf("Breakpoint at PC=0x%lx\n", sepc);
    80001532:	e55fe06f          	j	80000386 <printf>
            printf("Load address misaligned at PC=0x%lx, address=0x%lx\n", sepc, stval);
    80001536:	00004517          	auipc	a0,0x4
    8000153a:	7e250513          	add	a0,a0,2018 # 80005d18 <kalloc+0x75a>
    8000153e:	b7d9                	j	80001504 <handle_exception+0x42>
            printf("Load access fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    80001540:	00005517          	auipc	a0,0x5
    80001544:	81050513          	add	a0,a0,-2032 # 80005d50 <kalloc+0x792>
    80001548:	bf75                	j	80001504 <handle_exception+0x42>
            printf("Store address misaligned at PC=0x%lx, address=0x%lx\n", sepc, stval);
    8000154a:	00005517          	auipc	a0,0x5
    8000154e:	83650513          	add	a0,a0,-1994 # 80005d80 <kalloc+0x7c2>
    80001552:	bf4d                	j	80001504 <handle_exception+0x42>
            printf("Store access fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    80001554:	00005517          	auipc	a0,0x5
    80001558:	86450513          	add	a0,a0,-1948 # 80005db8 <kalloc+0x7fa>
    8000155c:	b765                	j	80001504 <handle_exception+0x42>
            printf("User mode environment call at PC=0x%lx\n", sepc);
    8000155e:	00004517          	auipc	a0,0x4
    80001562:	62250513          	add	a0,a0,1570 # 80005b80 <kalloc+0x5c2>
            printf("Supervisor mode environment call at PC=0x%lx\n", sepc);
    80001566:	e21fe0ef          	jal	80000386 <printf>

// 环境调用处理（系统调用）
void handle_ecall(uint64 sepc, uint64 stval) {
    printf("Environment call at PC=0x%lx\n", sepc);
    8000156a:	85a2                	mv	a1,s0
    8000156c:	00004517          	auipc	a0,0x4
    80001570:	63c50513          	add	a0,a0,1596 # 80005ba8 <kalloc+0x5ea>
    80001574:	e13fe0ef          	jal	80000386 <printf>
    
    // 获取系统调用号（通常在a7寄存器中）
    // 这里我们模拟系统调用处理
    printf("System call handling:\n");
    80001578:	00004517          	auipc	a0,0x4
    8000157c:	65050513          	add	a0,a0,1616 # 80005bc8 <kalloc+0x60a>
    80001580:	e07fe0ef          	jal	80000386 <printf>
    printf("  Call number: (would read from a7 register)\n");
    80001584:	00004517          	auipc	a0,0x4
    80001588:	65c50513          	add	a0,a0,1628 # 80005be0 <kalloc+0x622>
    8000158c:	dfbfe0ef          	jal	80000386 <printf>
    printf("  Arguments: (would read from a0-a6 registers)\n");
    80001590:	00004517          	auipc	a0,0x4
    80001594:	68050513          	add	a0,a0,1664 # 80005c10 <kalloc+0x652>
    80001598:	deffe0ef          	jal	80000386 <printf>
}
    8000159c:	6442                	ld	s0,16(sp)
    8000159e:	60e2                	ld	ra,24(sp)
    //     case SYS_EXIT: handle_sys_exit(); break;
    //     case SYS_WRITE: handle_sys_write(); break;
    //     default: printf("Unknown system call\n"); break;
    // }
    
    printf("System call handled\n");
    800015a0:	00004517          	auipc	a0,0x4
    800015a4:	6a050513          	add	a0,a0,1696 # 80005c40 <kalloc+0x682>
}
    800015a8:	6105                	add	sp,sp,32
    printf("System call handled\n");
    800015aa:	dddfe06f          	j	80000386 <printf>
            printf("Supervisor mode environment call at PC=0x%lx\n", sepc);
    800015ae:	00004517          	auipc	a0,0x4
    800015b2:	6aa50513          	add	a0,a0,1706 # 80005c58 <kalloc+0x69a>
    800015b6:	bf45                	j	80001566 <handle_exception+0xa4>
    printf("Instruction page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800015b8:	00004517          	auipc	a0,0x4
    800015bc:	30850513          	add	a0,a0,776 # 800058c0 <kalloc+0x302>
    800015c0:	e432                	sd	a2,8(sp)
    800015c2:	dc5fe0ef          	jal	80000386 <printf>
    if (stval < 0x80000000 || stval > 0x80000000 + 0x200000) {
    800015c6:	6622                	ld	a2,8(sp)
    800015c8:	800007b7          	lui	a5,0x80000
        w_sepc(sepc + 4);
    800015cc:	0411                	add	s0,s0,4
    if (stval < 0x80000000 || stval > 0x80000000 + 0x200000) {
    800015ce:	963e                	add	a2,a2,a5
    800015d0:	002007b7          	lui	a5,0x200
    800015d4:	06c7ef63          	bltu	a5,a2,80001652 <handle_exception+0x190>
    printf("Instruction page fault handled - would allocate page\n");
    800015d8:	00004517          	auipc	a0,0x4
    800015dc:	35850513          	add	a0,a0,856 # 80005930 <kalloc+0x372>
    800015e0:	da7fe0ef          	jal	80000386 <printf>
    800015e4:	14141073          	csrw	sepc,s0
}
    800015e8:	a08d                	j	8000164a <handle_exception+0x188>
    printf("Load page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    800015ea:	00004517          	auipc	a0,0x4
    800015ee:	37e50513          	add	a0,a0,894 # 80005968 <kalloc+0x3aa>
    800015f2:	e432                	sd	a2,8(sp)
    800015f4:	d93fe0ef          	jal	80000386 <printf>
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    800015f8:	6622                	ld	a2,8(sp)
    800015fa:	800007b7          	lui	a5,0x80000
   panic("Load page fault \n");
    800015fe:	00004517          	auipc	a0,0x4
    80001602:	3fa50513          	add	a0,a0,1018 # 800059f8 <kalloc+0x43a>
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    80001606:	963e                	add	a2,a2,a5
    80001608:	080007b7          	lui	a5,0x8000
    8000160c:	06c7e563          	bltu	a5,a2,80001676 <handle_exception+0x1b4>
}
    80001610:	6442                	ld	s0,16(sp)
    80001612:	60e2                	ld	ra,24(sp)
    80001614:	6105                	add	sp,sp,32
   panic("Load page fault \n");
    80001616:	b8aff06f          	j	800009a0 <panic>
    printf("Store page fault at PC=0x%lx, address=0x%lx\n", sepc, stval);
    8000161a:	00004517          	auipc	a0,0x4
    8000161e:	3f650513          	add	a0,a0,1014 # 80005a10 <kalloc+0x452>
    80001622:	e432                	sd	a2,8(sp)
    80001624:	d63fe0ef          	jal	80000386 <printf>
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    80001628:	6622                	ld	a2,8(sp)
    8000162a:	800007b7          	lui	a5,0x80000
        w_sepc(sepc + 4);
    8000162e:	0411                	add	s0,s0,4
    if (stval < 0x80000000 || stval > 0x80000000 + 0x8000000) {
    80001630:	963e                	add	a2,a2,a5
    80001632:	080007b7          	lui	a5,0x8000
    80001636:	02c7e763          	bltu	a5,a2,80001664 <handle_exception+0x1a2>
    printf("Store page fault handled - would allocate page\n");
    8000163a:	00004517          	auipc	a0,0x4
    8000163e:	43650513          	add	a0,a0,1078 # 80005a70 <kalloc+0x4b2>
    80001642:	d45fe0ef          	jal	80000386 <printf>
  asm volatile("csrw sepc, %0" : : "r" (x));
    80001646:	14141073          	csrw	sepc,s0
}
    8000164a:	60e2                	ld	ra,24(sp)
    8000164c:	6442                	ld	s0,16(sp)
    8000164e:	6105                	add	sp,sp,32
    80001650:	8082                	ret
        printf("FATAL: Instruction page fault at invalid address\n");
    80001652:	00004517          	auipc	a0,0x4
    80001656:	2a650513          	add	a0,a0,678 # 800058f8 <kalloc+0x33a>
    8000165a:	d2dfe0ef          	jal	80000386 <printf>
    8000165e:	14141073          	csrw	sepc,s0
        return;
    80001662:	b7e5                	j	8000164a <handle_exception+0x188>
        printf("FATAL: Store page fault at invalid address\n");
    80001664:	00004517          	auipc	a0,0x4
    80001668:	3dc50513          	add	a0,a0,988 # 80005a40 <kalloc+0x482>
    8000166c:	d1bfe0ef          	jal	80000386 <printf>
    80001670:	14141073          	csrw	sepc,s0
        return;
    80001674:	bfd9                	j	8000164a <handle_exception+0x188>
        printf("FATAL: Load page fault at invalid address\n");
    80001676:	00004517          	auipc	a0,0x4
    8000167a:	32250513          	add	a0,a0,802 # 80005998 <kalloc+0x3da>
    8000167e:	d09fe0ef          	jal	80000386 <printf>
        panic("Load page fault at invalid address,exiting...");
    80001682:	00004517          	auipc	a0,0x4
    80001686:	34650513          	add	a0,a0,838 # 800059c8 <kalloc+0x40a>
    8000168a:	b759                	j	80001610 <handle_exception+0x14e>

000000008000168c <kerneltrap>:
void kerneltrap(void) {
    8000168c:	1101                	add	sp,sp,-32
    8000168e:	ec06                	sd	ra,24(sp)
    80001690:	e822                	sd	s0,16(sp)
    80001692:	e426                	sd	s1,8(sp)
    80001694:	e04a                	sd	s2,0(sp)
  asm volatile("csrr %0, sepc" : "=r" (x) );
    80001696:	141024f3          	csrr	s1,sepc
  asm volatile("csrr %0, scause" : "=r" (x) );
    8000169a:	14202473          	csrr	s0,scause
  asm volatile("csrr %0, stval" : "=r" (x) );
    8000169e:	14302973          	csrr	s2,stval
    printf("kerneltrap\n");
    800016a2:	00004517          	auipc	a0,0x4
    800016a6:	77e50513          	add	a0,a0,1918 # 80005e20 <kalloc+0x862>
    800016aa:	cddfe0ef          	jal	80000386 <printf>
    if (scause & (1UL << 63)) {
    800016ae:	04045163          	bgez	s0,800016f0 <kerneltrap+0x64>
        if (irq < MAX_IRQ && irq_table[irq]) {
    800016b2:	0f047793          	and	a5,s0,240
        uint64 irq = scause & 0xFF;
    800016b6:	0ff47593          	zext.b	a1,s0
        if (irq < MAX_IRQ && irq_table[irq]) {
    800016ba:	e385                	bnez	a5,800016da <kerneltrap+0x4e>
    800016bc:	00359713          	sll	a4,a1,0x3
    800016c0:	00005797          	auipc	a5,0x5
    800016c4:	02078793          	add	a5,a5,32 # 800066e0 <irq_table>
    800016c8:	97ba                	add	a5,a5,a4
    800016ca:	639c                	ld	a5,0(a5)
    800016cc:	c799                	beqz	a5,800016da <kerneltrap+0x4e>
}
    800016ce:	6442                	ld	s0,16(sp)
    800016d0:	60e2                	ld	ra,24(sp)
    800016d2:	64a2                	ld	s1,8(sp)
    800016d4:	6902                	ld	s2,0(sp)
    800016d6:	6105                	add	sp,sp,32
            irq_table[irq]();
    800016d8:	8782                	jr	a5
}
    800016da:	6442                	ld	s0,16(sp)
    800016dc:	60e2                	ld	ra,24(sp)
    800016de:	64a2                	ld	s1,8(sp)
    800016e0:	6902                	ld	s2,0(sp)
            printf("Unhandled interrupt: %lu\n", irq);
    800016e2:	00004517          	auipc	a0,0x4
    800016e6:	74e50513          	add	a0,a0,1870 # 80005e30 <kalloc+0x872>
}
    800016ea:	6105                	add	sp,sp,32
            printf("Unhandled interrupt: %lu\n", irq);
    800016ec:	c9bfe06f          	j	80000386 <printf>
        handle_exception(scause, sepc, stval);
    800016f0:	8522                	mv	a0,s0
}
    800016f2:	6442                	ld	s0,16(sp)
    800016f4:	60e2                	ld	ra,24(sp)
        handle_exception(scause, sepc, stval);
    800016f6:	864a                	mv	a2,s2
    800016f8:	85a6                	mv	a1,s1
}
    800016fa:	6902                	ld	s2,0(sp)
    800016fc:	64a2                	ld	s1,8(sp)
    800016fe:	6105                	add	sp,sp,32
        handle_exception(scause, sepc, stval);
    80001700:	b3c9                	j	800014c2 <handle_exception>

0000000080001702 <handle_ecall>:
void handle_ecall(uint64 sepc, uint64 stval) {
    80001702:	1141                	add	sp,sp,-16
    80001704:	85aa                	mv	a1,a0
    printf("Environment call at PC=0x%lx\n", sepc);
    80001706:	00004517          	auipc	a0,0x4
    8000170a:	4a250513          	add	a0,a0,1186 # 80005ba8 <kalloc+0x5ea>
void handle_ecall(uint64 sepc, uint64 stval) {
    8000170e:	e406                	sd	ra,8(sp)
    printf("Environment call at PC=0x%lx\n", sepc);
    80001710:	c77fe0ef          	jal	80000386 <printf>
    printf("System call handling:\n");
    80001714:	00004517          	auipc	a0,0x4
    80001718:	4b450513          	add	a0,a0,1204 # 80005bc8 <kalloc+0x60a>
    8000171c:	c6bfe0ef          	jal	80000386 <printf>
    printf("  Call number: (would read from a7 register)\n");
    80001720:	00004517          	auipc	a0,0x4
    80001724:	4c050513          	add	a0,a0,1216 # 80005be0 <kalloc+0x622>
    80001728:	c5ffe0ef          	jal	80000386 <printf>
    printf("  Arguments: (would read from a0-a6 registers)\n");
    8000172c:	00004517          	auipc	a0,0x4
    80001730:	4e450513          	add	a0,a0,1252 # 80005c10 <kalloc+0x652>
    80001734:	c53fe0ef          	jal	80000386 <printf>
}
    80001738:	60a2                	ld	ra,8(sp)
    printf("System call handled\n");
    8000173a:	00004517          	auipc	a0,0x4
    8000173e:	50650513          	add	a0,a0,1286 # 80005c40 <kalloc+0x682>
}
    80001742:	0141                	add	sp,sp,16
    printf("System call handled\n");
    80001744:	c43fe06f          	j	80000386 <printf>

0000000080001748 <prepare_return>:
//
// set up trapframe and control registers for a return to user space
//
void
prepare_return(void)
{
    80001748:	1141                	add	sp,sp,-16
    8000174a:	e406                	sd	ra,8(sp)
  struct proc *p = myproc();
    8000174c:	617000ef          	jal	80002562 <myproc>
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80001750:	100027f3          	csrr	a5,sstatus

// disable device interrupts
static inline void
intr_off()
{
  w_sstatus(r_sstatus() & ~SSTATUS_SIE);
    80001754:	9bf5                	and	a5,a5,-3
  asm volatile("csrw sstatus, %0" : : "r" (x));
    80001756:	10079073          	csrw	sstatus,a5
  // kerneltrap() to usertrap(). because a trap from kernel
  // code to usertrap would be a disaster, turn off interrupts.
  intr_off();

  // send syscalls, interrupts, and exceptions to uservec in trampoline.S
  uint64 trampoline_uservec = TRAMPOLINE + (uservec - trampoline);
    8000175a:	04000737          	lui	a4,0x4000
    8000175e:	00017697          	auipc	a3,0x17
    80001762:	8a268693          	add	a3,a3,-1886 # 80018000 <trampoline>
    80001766:	00017797          	auipc	a5,0x17
    8000176a:	89a78793          	add	a5,a5,-1894 # 80018000 <trampoline>
    8000176e:	177d                	add	a4,a4,-1 # 3ffffff <_entry-0x7c000001>
    80001770:	8f95                	sub	a5,a5,a3
    80001772:	0732                	sll	a4,a4,0xc
    80001774:	97ba                	add	a5,a5,a4
  asm volatile("csrw stvec, %0" : : "r" (x));
    80001776:	10579073          	csrw	stvec,a5
  w_stvec(trampoline_uservec);

  // set up trapframe values that uservec will need when
  // the process next traps into the kernel.
  p->trapframe->kernel_satp = r_satp();         // kernel page table
    8000177a:	613c                	ld	a5,64(a0)
  asm volatile("csrr %0, satp" : "=r" (x) );
    8000177c:	180026f3          	csrr	a3,satp
  p->trapframe->kernel_sp = p->kstack + PGSIZE; // process's kernel stack
    80001780:	7d58                	ld	a4,184(a0)
    80001782:	6605                	lui	a2,0x1
  p->trapframe->kernel_satp = r_satp();         // kernel page table
    80001784:	e394                	sd	a3,0(a5)
  p->trapframe->kernel_sp = p->kstack + PGSIZE; // process's kernel stack
    80001786:	9732                	add	a4,a4,a2
    80001788:	e798                	sd	a4,8(a5)
  p->trapframe->kernel_trap = (uint64)usertrap;
    8000178a:	00000717          	auipc	a4,0x0
    8000178e:	02a70713          	add	a4,a4,42 # 800017b4 <usertrap>
    80001792:	eb98                	sd	a4,16(a5)
// this core's hartid (core number), the index into cpus[].
static inline uint64
r_tp()
{
  uint64 x;
  asm volatile("mv %0, tp" : "=r" (x) );
    80001794:	8712                	mv	a4,tp
  p->trapframe->kernel_hartid = r_tp();         // hartid for cpuid()
    80001796:	f398                	sd	a4,32(a5)
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80001798:	10002773          	csrr	a4,sstatus
  // set up the registers that trampoline.S's sret will use
  // to get to user space.
  
  // set S Previous Privilege mode to User.
  unsigned long x = r_sstatus();
  x &= ~SSTATUS_SPP; // clear SPP to 0 for user mode
    8000179c:	eff77713          	and	a4,a4,-257
  x |= SSTATUS_SPIE; // enable interrupts in user mode
    800017a0:	02076713          	or	a4,a4,32
  asm volatile("csrw sstatus, %0" : : "r" (x));
    800017a4:	10071073          	csrw	sstatus,a4
  asm volatile("csrw sepc, %0" : : "r" (x));
    800017a8:	6f9c                	ld	a5,24(a5)
    800017aa:	14179073          	csrw	sepc,a5
  w_sstatus(x);
  
  // set S Exception Program Counter to the saved user pc.
  w_sepc(p->trapframe->epc);
}
    800017ae:	60a2                	ld	ra,8(sp)
    800017b0:	0141                	add	sp,sp,16
    800017b2:	8082                	ret

00000000800017b4 <usertrap>:
uint64 usertrap(void) {
    800017b4:	7179                	add	sp,sp,-48
    800017b6:	f406                	sd	ra,40(sp)
    800017b8:	f022                	sd	s0,32(sp)
    800017ba:	ec26                	sd	s1,24(sp)
    800017bc:	e84a                	sd	s2,16(sp)
    800017be:	e44e                	sd	s3,8(sp)
  asm volatile("csrr %0, scause" : "=r" (x) );
    800017c0:	142024f3          	csrr	s1,scause
  asm volatile("csrr %0, sepc" : "=r" (x) );
    800017c4:	14102973          	csrr	s2,sepc
  asm volatile("csrr %0, stval" : "=r" (x) );
    800017c8:	143029f3          	csrr	s3,stval
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    800017cc:	100027f3          	csrr	a5,sstatus
    if((r_sstatus() & SSTATUS_SPP) != 0)
    800017d0:	1007f793          	and	a5,a5,256
    800017d4:	e7d5                	bnez	a5,80001880 <usertrap+0xcc>
  asm volatile("csrw stvec, %0" : : "r" (x));
    800017d6:	00000797          	auipc	a5,0x0
    800017da:	98a78793          	add	a5,a5,-1654 # 80001160 <kernelvec>
    800017de:	10579073          	csrw	stvec,a5
    struct proc *p = myproc();
    800017e2:	581000ef          	jal	80002562 <myproc>
    p->trapframe->epc = sepc;
    800017e6:	6138                	ld	a4,64(a0)
    if(scause == EXC_ECALL_U_MODE){
    800017e8:	47a1                	li	a5,8
    struct proc *p = myproc();
    800017ea:	842a                	mv	s0,a0
    p->trapframe->epc = sepc;
    800017ec:	01273c23          	sd	s2,24(a4)
    if(scause == EXC_ECALL_U_MODE){
    800017f0:	0af48963          	beq	s1,a5,800018a2 <usertrap+0xee>
    } else if(scause & (1UL << 63)) {
    800017f4:	0404cc63          	bltz	s1,8000184c <usertrap+0x98>
    } else if((scause == EXC_LOAD_PAGE_FAULT || scause == EXC_STORE_PAGE_FAULT) &&
    800017f8:	ffd4f793          	and	a5,s1,-3
    800017fc:	4735                	li	a4,13
    800017fe:	08e78863          	beq	a5,a4,8000188e <usertrap+0xda>
      printf("usertrap(): unexpected scause 0x%lx pid=%d\n", scause, p->pid);
    80001802:	5810                	lw	a2,48(s0)
    80001804:	85a6                	mv	a1,s1
    80001806:	00004517          	auipc	a0,0x4
    8000180a:	69250513          	add	a0,a0,1682 # 80005e98 <kalloc+0x8da>
    8000180e:	b79fe0ef          	jal	80000386 <printf>
      printf("            sepc=0x%lx stval=0x%lx\n", sepc, stval);
    80001812:	864e                	mv	a2,s3
    80001814:	85ca                	mv	a1,s2
    80001816:	00004517          	auipc	a0,0x4
    8000181a:	6b250513          	add	a0,a0,1714 # 80005ec8 <kalloc+0x90a>
    8000181e:	b69fe0ef          	jal	80000386 <printf>
      setkilled(p);
    80001822:	8522                	mv	a0,s0
    80001824:	5d8010ef          	jal	80002dfc <setkilled>
    if(killed(p))
    80001828:	8522                	mv	a0,s0
    8000182a:	5ee010ef          	jal	80002e18 <killed>
    8000182e:	e529                	bnez	a0,80001878 <usertrap+0xc4>
    prepare_return();
    80001830:	f19ff0ef          	jal	80001748 <prepare_return>
    uint64 satp = MAKE_SATP(p->pagetable);
    80001834:	6468                	ld	a0,200(s0)
}
    80001836:	70a2                	ld	ra,40(sp)
    80001838:	7402                	ld	s0,32(sp)
    8000183a:	57fd                	li	a5,-1
    uint64 satp = MAKE_SATP(p->pagetable);
    8000183c:	8131                	srl	a0,a0,0xc
}
    8000183e:	17fe                	sll	a5,a5,0x3f
    80001840:	64e2                	ld	s1,24(sp)
    80001842:	6942                	ld	s2,16(sp)
    80001844:	69a2                	ld	s3,8(sp)
    80001846:	8d5d                	or	a0,a0,a5
    80001848:	6145                	add	sp,sp,48
    8000184a:	8082                	ret
      uint64 irq = scause & 0xFF;
    8000184c:	0ff4f593          	zext.b	a1,s1
      if (irq == IRQ_S_TIMER) {
    80001850:	4795                	li	a5,5
    80001852:	08f58663          	beq	a1,a5,800018de <usertrap+0x12a>
      } else if (irq < MAX_IRQ && irq_table[irq]) {
    80001856:	0f04f493          	and	s1,s1,240
    8000185a:	e4a5                	bnez	s1,800018c2 <usertrap+0x10e>
    8000185c:	00359713          	sll	a4,a1,0x3
    80001860:	00005797          	auipc	a5,0x5
    80001864:	e8078793          	add	a5,a5,-384 # 800066e0 <irq_table>
    80001868:	97ba                	add	a5,a5,a4
    8000186a:	639c                	ld	a5,0(a5)
    8000186c:	cbb9                	beqz	a5,800018c2 <usertrap+0x10e>
        irq_table[irq]();
    8000186e:	9782                	jalr	a5
    if(killed(p))
    80001870:	8522                	mv	a0,s0
    80001872:	5a6010ef          	jal	80002e18 <killed>
    80001876:	dd4d                	beqz	a0,80001830 <usertrap+0x7c>
      exit(-1);
    80001878:	557d                	li	a0,-1
    8000187a:	156010ef          	jal	800029d0 <exit>
    8000187e:	bf4d                	j	80001830 <usertrap+0x7c>
    panic("usertrap: not from user mode");
    80001880:	00004517          	auipc	a0,0x4
    80001884:	5d050513          	add	a0,a0,1488 # 80005e50 <kalloc+0x892>
    80001888:	918ff0ef          	jal	800009a0 <panic>
    8000188c:	b7a9                	j	800017d6 <usertrap+0x22>
              vmfault(p->pagetable, stval, (scause == EXC_LOAD_PAGE_FAULT)? 1 : 0) != 0) {
    8000188e:	6568                	ld	a0,200(a0)
    80001890:	ff348613          	add	a2,s1,-13
    80001894:	00163613          	seqz	a2,a2
    80001898:	85ce                	mv	a1,s3
    8000189a:	807ff0ef          	jal	800010a0 <vmfault>
    } else if((scause == EXC_LOAD_PAGE_FAULT || scause == EXC_STORE_PAGE_FAULT) &&
    8000189e:	d135                	beqz	a0,80001802 <usertrap+0x4e>
    800018a0:	b761                	j	80001828 <usertrap+0x74>
      if(killed(p))
    800018a2:	576010ef          	jal	80002e18 <killed>
    800018a6:	e905                	bnez	a0,800018d6 <usertrap+0x122>
      p->trapframe->epc += 4;
    800018a8:	6038                	ld	a4,64(s0)
    800018aa:	6f1c                	ld	a5,24(a4)
    800018ac:	0791                	add	a5,a5,4
    800018ae:	ef1c                	sd	a5,24(a4)
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    800018b0:	100027f3          	csrr	a5,sstatus
  w_sstatus(r_sstatus() | SSTATUS_SIE);
    800018b4:	0027e793          	or	a5,a5,2
  asm volatile("csrw sstatus, %0" : : "r" (x));
    800018b8:	10079073          	csrw	sstatus,a5
      syscall();
    800018bc:	2a6000ef          	jal	80001b62 <syscall>
    800018c0:	b7a5                	j	80001828 <usertrap+0x74>
        printf("usertrap(): unexpected interrupt %lu\n", irq);
    800018c2:	00004517          	auipc	a0,0x4
    800018c6:	5ae50513          	add	a0,a0,1454 # 80005e70 <kalloc+0x8b2>
    800018ca:	abdfe0ef          	jal	80000386 <printf>
        setkilled(p);
    800018ce:	8522                	mv	a0,s0
    800018d0:	52c010ef          	jal	80002dfc <setkilled>
    800018d4:	bf91                	j	80001828 <usertrap+0x74>
        exit(-1);
    800018d6:	557d                	li	a0,-1
    800018d8:	0f8010ef          	jal	800029d0 <exit>
    800018dc:	b7f1                	j	800018a8 <usertrap+0xf4>
        handle_timer();
    800018de:	8f9ff0ef          	jal	800011d6 <handle_timer>
        if(killed(p))
    800018e2:	8522                	mv	a0,s0
    800018e4:	534010ef          	jal	80002e18 <killed>
    800018e8:	e501                	bnez	a0,800018f0 <usertrap+0x13c>
        yield();
    800018ea:	6f1000ef          	jal	800027da <yield>
    800018ee:	bf2d                	j	80001828 <usertrap+0x74>
          exit(-1);
    800018f0:	557d                	li	a0,-1
    800018f2:	0de010ef          	jal	800029d0 <exit>
    800018f6:	bfd5                	j	800018ea <usertrap+0x136>

00000000800018f8 <get_time>:
  asm volatile("csrr %0, time" : "=r" (x) );
    800018f8:	c0102573          	rdtime	a0
// SBI时钟接口实现

// 获取当前时间
uint64 get_time(void) {
    return r_time();
}
    800018fc:	8082                	ret

00000000800018fe <sbi_set_timer>:
   asm volatile("csrw 0x14d, %0" : : "r" (x));
    800018fe:	14d51073          	csrw	stimecmp,a0

// 设置下次时钟中断时间
void sbi_set_timer(uint64 time) {
    w_stimecmp(time);
}
    80001902:	8082                	ret

0000000080001904 <fetchaddr>:
#include "syscall.h"

// Fetch the uint64 at addr from the current process.
int
fetchaddr(uint64 addr, uint64 *ip)
{
    80001904:	1101                	add	sp,sp,-32
    80001906:	e822                	sd	s0,16(sp)
    80001908:	e426                	sd	s1,8(sp)
    8000190a:	ec06                	sd	ra,24(sp)
    8000190c:	842a                	mv	s0,a0
    8000190e:	84ae                	mv	s1,a1
  struct proc *p = myproc();
    80001910:	453000ef          	jal	80002562 <myproc>
  if(addr >= p->sz || addr+sizeof(uint64) > p->sz) // both tests needed, in case of overflow
    80001914:	617c                	ld	a5,192(a0)
    80001916:	02f47563          	bgeu	s0,a5,80001940 <fetchaddr+0x3c>
    8000191a:	00840713          	add	a4,s0,8
    8000191e:	02e7e163          	bltu	a5,a4,80001940 <fetchaddr+0x3c>
    return -1;
  if(copyin(p->pagetable, (char *)ip, addr, sizeof(*ip)) != 0)
    80001922:	6568                	ld	a0,200(a0)
    80001924:	46a1                	li	a3,8
    80001926:	8622                	mv	a2,s0
    80001928:	85a6                	mv	a1,s1
    8000192a:	2f6010ef          	jal	80002c20 <copyin>
    8000192e:	00a03533          	snez	a0,a0
    80001932:	40a00533          	neg	a0,a0
    return -1;
  return 0;
}
    80001936:	60e2                	ld	ra,24(sp)
    80001938:	6442                	ld	s0,16(sp)
    8000193a:	64a2                	ld	s1,8(sp)
    8000193c:	6105                	add	sp,sp,32
    8000193e:	8082                	ret
    return -1;
    80001940:	557d                	li	a0,-1
    80001942:	bfd5                	j	80001936 <fetchaddr+0x32>

0000000080001944 <fetchstr>:

// Fetch the nul-terminated string at addr from the current process.
// Returns length of string, not including nul, or -1 for error.
int
fetchstr(uint64 addr, char *buf, int max)
{
    80001944:	1101                	add	sp,sp,-32
    80001946:	e822                	sd	s0,16(sp)
    80001948:	e426                	sd	s1,8(sp)
    8000194a:	e04a                	sd	s2,0(sp)
    8000194c:	ec06                	sd	ra,24(sp)
    8000194e:	8932                	mv	s2,a2
    80001950:	84aa                	mv	s1,a0
    80001952:	842e                	mv	s0,a1
  struct proc *p = myproc();
    80001954:	40f000ef          	jal	80002562 <myproc>
  if(copyinstr(p->pagetable, buf, addr, max) < 0)
    80001958:	6568                	ld	a0,200(a0)
    8000195a:	86ca                	mv	a3,s2
    8000195c:	8626                	mv	a2,s1
    8000195e:	85a2                	mv	a1,s0
    80001960:	3d6010ef          	jal	80002d36 <copyinstr>
    80001964:	00054a63          	bltz	a0,80001978 <fetchstr+0x34>
    return -1;
  return strlen(buf);
    80001968:	8522                	mv	a0,s0
}
    8000196a:	6442                	ld	s0,16(sp)
    8000196c:	60e2                	ld	ra,24(sp)
    8000196e:	64a2                	ld	s1,8(sp)
    80001970:	6902                	ld	s2,0(sp)
    80001972:	6105                	add	sp,sp,32
  return strlen(buf);
    80001974:	33d0306f          	j	800054b0 <strlen>
}
    80001978:	60e2                	ld	ra,24(sp)
    8000197a:	6442                	ld	s0,16(sp)
    8000197c:	64a2                	ld	s1,8(sp)
    8000197e:	6902                	ld	s2,0(sp)
    80001980:	557d                	li	a0,-1
    80001982:	6105                	add	sp,sp,32
    80001984:	8082                	ret

0000000080001986 <argint>:
}

// Fetch the nth 32-bit system call argument.
void
argint(int n, int *ip)
{
    80001986:	1101                	add	sp,sp,-32
    80001988:	e822                	sd	s0,16(sp)
    8000198a:	e426                	sd	s1,8(sp)
    8000198c:	ec06                	sd	ra,24(sp)
    8000198e:	842a                	mv	s0,a0
    80001990:	84ae                	mv	s1,a1
  struct proc *p = myproc();
    80001992:	3d1000ef          	jal	80002562 <myproc>
  switch (n) {
    80001996:	4795                	li	a5,5
    80001998:	0687ef63          	bltu	a5,s0,80001a16 <argint+0x90>
    8000199c:	00004717          	auipc	a4,0x4
    800019a0:	5cc70713          	add	a4,a4,1484 # 80005f68 <kalloc+0x9aa>
    800019a4:	040a                	sll	s0,s0,0x2
    800019a6:	943a                	add	s0,s0,a4
    800019a8:	401c                	lw	a5,0(s0)
    800019aa:	97ba                	add	a5,a5,a4
    800019ac:	8782                	jr	a5
    return p->trapframe->a4;
    800019ae:	613c                	ld	a5,64(a0)
  *ip = argraw(n);
}
    800019b0:	60e2                	ld	ra,24(sp)
    800019b2:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    800019b4:	0907a783          	lw	a5,144(a5)
    800019b8:	c09c                	sw	a5,0(s1)
}
    800019ba:	64a2                	ld	s1,8(sp)
    800019bc:	6105                	add	sp,sp,32
    800019be:	8082                	ret
    return p->trapframe->a5;
    800019c0:	613c                	ld	a5,64(a0)
}
    800019c2:	60e2                	ld	ra,24(sp)
    800019c4:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    800019c6:	0987a783          	lw	a5,152(a5)
    800019ca:	c09c                	sw	a5,0(s1)
}
    800019cc:	64a2                	ld	s1,8(sp)
    800019ce:	6105                	add	sp,sp,32
    800019d0:	8082                	ret
    return p->trapframe->a0;
    800019d2:	613c                	ld	a5,64(a0)
}
    800019d4:	60e2                	ld	ra,24(sp)
    800019d6:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    800019d8:	5bbc                	lw	a5,112(a5)
    800019da:	c09c                	sw	a5,0(s1)
}
    800019dc:	64a2                	ld	s1,8(sp)
    800019de:	6105                	add	sp,sp,32
    800019e0:	8082                	ret
    return p->trapframe->a1;
    800019e2:	613c                	ld	a5,64(a0)
}
    800019e4:	60e2                	ld	ra,24(sp)
    800019e6:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    800019e8:	5fbc                	lw	a5,120(a5)
    800019ea:	c09c                	sw	a5,0(s1)
}
    800019ec:	64a2                	ld	s1,8(sp)
    800019ee:	6105                	add	sp,sp,32
    800019f0:	8082                	ret
    return p->trapframe->a2;
    800019f2:	613c                	ld	a5,64(a0)
}
    800019f4:	60e2                	ld	ra,24(sp)
    800019f6:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    800019f8:	0807a783          	lw	a5,128(a5)
    800019fc:	c09c                	sw	a5,0(s1)
}
    800019fe:	64a2                	ld	s1,8(sp)
    80001a00:	6105                	add	sp,sp,32
    80001a02:	8082                	ret
    return p->trapframe->a3;
    80001a04:	613c                	ld	a5,64(a0)
}
    80001a06:	60e2                	ld	ra,24(sp)
    80001a08:	6442                	ld	s0,16(sp)
  *ip = argraw(n);
    80001a0a:	0887a783          	lw	a5,136(a5)
    80001a0e:	c09c                	sw	a5,0(s1)
}
    80001a10:	64a2                	ld	s1,8(sp)
    80001a12:	6105                	add	sp,sp,32
    80001a14:	8082                	ret
  panic("argraw");
    80001a16:	00004517          	auipc	a0,0x4
    80001a1a:	51a50513          	add	a0,a0,1306 # 80005f30 <kalloc+0x972>
    80001a1e:	f83fe0ef          	jal	800009a0 <panic>
}
    80001a22:	60e2                	ld	ra,24(sp)
    80001a24:	6442                	ld	s0,16(sp)
  return -1;
    80001a26:	57fd                	li	a5,-1
  *ip = argraw(n);
    80001a28:	c09c                	sw	a5,0(s1)
}
    80001a2a:	64a2                	ld	s1,8(sp)
    80001a2c:	6105                	add	sp,sp,32
    80001a2e:	8082                	ret

0000000080001a30 <argaddr>:
// Retrieve an argument as a pointer.
// Doesn't check for legality, since
// copyin/copyout will do that.
void
argaddr(int n, uint64 *ip)
{
    80001a30:	1101                	add	sp,sp,-32
    80001a32:	e822                	sd	s0,16(sp)
    80001a34:	e426                	sd	s1,8(sp)
    80001a36:	ec06                	sd	ra,24(sp)
    80001a38:	842a                	mv	s0,a0
    80001a3a:	84ae                	mv	s1,a1
  struct proc *p = myproc();
    80001a3c:	327000ef          	jal	80002562 <myproc>
  switch (n) {
    80001a40:	4795                	li	a5,5
    80001a42:	0687eb63          	bltu	a5,s0,80001ab8 <argaddr+0x88>
    80001a46:	00004717          	auipc	a4,0x4
    80001a4a:	53a70713          	add	a4,a4,1338 # 80005f80 <kalloc+0x9c2>
    80001a4e:	040a                	sll	s0,s0,0x2
    80001a50:	943a                	add	s0,s0,a4
    80001a52:	401c                	lw	a5,0(s0)
    80001a54:	97ba                	add	a5,a5,a4
    80001a56:	8782                	jr	a5
    return p->trapframe->a4;
    80001a58:	613c                	ld	a5,64(a0)
  *ip = argraw(n);
}
    80001a5a:	60e2                	ld	ra,24(sp)
    80001a5c:	6442                	ld	s0,16(sp)
    return p->trapframe->a4;
    80001a5e:	6bdc                	ld	a5,144(a5)
  *ip = argraw(n);
    80001a60:	e09c                	sd	a5,0(s1)
}
    80001a62:	64a2                	ld	s1,8(sp)
    80001a64:	6105                	add	sp,sp,32
    80001a66:	8082                	ret
    return p->trapframe->a5;
    80001a68:	613c                	ld	a5,64(a0)
}
    80001a6a:	60e2                	ld	ra,24(sp)
    80001a6c:	6442                	ld	s0,16(sp)
    return p->trapframe->a5;
    80001a6e:	6fdc                	ld	a5,152(a5)
  *ip = argraw(n);
    80001a70:	e09c                	sd	a5,0(s1)
}
    80001a72:	64a2                	ld	s1,8(sp)
    80001a74:	6105                	add	sp,sp,32
    80001a76:	8082                	ret
    return p->trapframe->a0;
    80001a78:	613c                	ld	a5,64(a0)
}
    80001a7a:	60e2                	ld	ra,24(sp)
    80001a7c:	6442                	ld	s0,16(sp)
    return p->trapframe->a0;
    80001a7e:	7bbc                	ld	a5,112(a5)
  *ip = argraw(n);
    80001a80:	e09c                	sd	a5,0(s1)
}
    80001a82:	64a2                	ld	s1,8(sp)
    80001a84:	6105                	add	sp,sp,32
    80001a86:	8082                	ret
    return p->trapframe->a1;
    80001a88:	613c                	ld	a5,64(a0)
}
    80001a8a:	60e2                	ld	ra,24(sp)
    80001a8c:	6442                	ld	s0,16(sp)
    return p->trapframe->a1;
    80001a8e:	7fbc                	ld	a5,120(a5)
  *ip = argraw(n);
    80001a90:	e09c                	sd	a5,0(s1)
}
    80001a92:	64a2                	ld	s1,8(sp)
    80001a94:	6105                	add	sp,sp,32
    80001a96:	8082                	ret
    return p->trapframe->a2;
    80001a98:	613c                	ld	a5,64(a0)
}
    80001a9a:	60e2                	ld	ra,24(sp)
    80001a9c:	6442                	ld	s0,16(sp)
    return p->trapframe->a2;
    80001a9e:	63dc                	ld	a5,128(a5)
  *ip = argraw(n);
    80001aa0:	e09c                	sd	a5,0(s1)
}
    80001aa2:	64a2                	ld	s1,8(sp)
    80001aa4:	6105                	add	sp,sp,32
    80001aa6:	8082                	ret
    return p->trapframe->a3;
    80001aa8:	613c                	ld	a5,64(a0)
}
    80001aaa:	60e2                	ld	ra,24(sp)
    80001aac:	6442                	ld	s0,16(sp)
    return p->trapframe->a3;
    80001aae:	67dc                	ld	a5,136(a5)
  *ip = argraw(n);
    80001ab0:	e09c                	sd	a5,0(s1)
}
    80001ab2:	64a2                	ld	s1,8(sp)
    80001ab4:	6105                	add	sp,sp,32
    80001ab6:	8082                	ret
  panic("argraw");
    80001ab8:	00004517          	auipc	a0,0x4
    80001abc:	47850513          	add	a0,a0,1144 # 80005f30 <kalloc+0x972>
    80001ac0:	ee1fe0ef          	jal	800009a0 <panic>
}
    80001ac4:	60e2                	ld	ra,24(sp)
    80001ac6:	6442                	ld	s0,16(sp)
  return -1;
    80001ac8:	57fd                	li	a5,-1
  *ip = argraw(n);
    80001aca:	e09c                	sd	a5,0(s1)
}
    80001acc:	64a2                	ld	s1,8(sp)
    80001ace:	6105                	add	sp,sp,32
    80001ad0:	8082                	ret

0000000080001ad2 <argstr>:
// Fetch the nth word-sized system call argument as a null-terminated string.
// Copies into buf, at most max.
// Returns string length if OK (including nul), -1 if error.
int
argstr(int n, char *buf, int max)
{
    80001ad2:	1101                	add	sp,sp,-32
    80001ad4:	e822                	sd	s0,16(sp)
    80001ad6:	e426                	sd	s1,8(sp)
    80001ad8:	e04a                	sd	s2,0(sp)
    80001ada:	ec06                	sd	ra,24(sp)
    80001adc:	842a                	mv	s0,a0
    80001ade:	84ae                	mv	s1,a1
    80001ae0:	8932                	mv	s2,a2
  struct proc *p = myproc();
    80001ae2:	281000ef          	jal	80002562 <myproc>
  switch (n) {
    80001ae6:	4795                	li	a5,5
    80001ae8:	0487ee63          	bltu	a5,s0,80001b44 <argstr+0x72>
    80001aec:	00004717          	auipc	a4,0x4
    80001af0:	4ac70713          	add	a4,a4,1196 # 80005f98 <kalloc+0x9da>
    80001af4:	040a                	sll	s0,s0,0x2
    80001af6:	943a                	add	s0,s0,a4
    80001af8:	401c                	lw	a5,0(s0)
    80001afa:	97ba                	add	a5,a5,a4
    80001afc:	8782                	jr	a5
    return p->trapframe->a4;
    80001afe:	613c                	ld	a5,64(a0)
    80001b00:	6bc0                	ld	s0,144(a5)
  struct proc *p = myproc();
    80001b02:	261000ef          	jal	80002562 <myproc>
  if(copyinstr(p->pagetable, buf, addr, max) < 0)
    80001b06:	6568                	ld	a0,200(a0)
    80001b08:	86ca                	mv	a3,s2
    80001b0a:	8622                	mv	a2,s0
    80001b0c:	85a6                	mv	a1,s1
    80001b0e:	228010ef          	jal	80002d36 <copyinstr>
    80001b12:	04054163          	bltz	a0,80001b54 <argstr+0x82>
  uint64 addr;
  argaddr(n, &addr);
  return fetchstr(addr, buf, max);
}
    80001b16:	6442                	ld	s0,16(sp)
    80001b18:	60e2                	ld	ra,24(sp)
    80001b1a:	6902                	ld	s2,0(sp)
  return strlen(buf);
    80001b1c:	8526                	mv	a0,s1
}
    80001b1e:	64a2                	ld	s1,8(sp)
    80001b20:	6105                	add	sp,sp,32
  return strlen(buf);
    80001b22:	18f0306f          	j	800054b0 <strlen>
    return p->trapframe->a5;
    80001b26:	613c                	ld	a5,64(a0)
    80001b28:	6fc0                	ld	s0,152(a5)
    80001b2a:	bfe1                	j	80001b02 <argstr+0x30>
    return p->trapframe->a0;
    80001b2c:	613c                	ld	a5,64(a0)
    80001b2e:	7ba0                	ld	s0,112(a5)
    80001b30:	bfc9                	j	80001b02 <argstr+0x30>
    return p->trapframe->a1;
    80001b32:	613c                	ld	a5,64(a0)
    80001b34:	7fa0                	ld	s0,120(a5)
    80001b36:	b7f1                	j	80001b02 <argstr+0x30>
    return p->trapframe->a2;
    80001b38:	613c                	ld	a5,64(a0)
    80001b3a:	63c0                	ld	s0,128(a5)
    80001b3c:	b7d9                	j	80001b02 <argstr+0x30>
    return p->trapframe->a3;
    80001b3e:	613c                	ld	a5,64(a0)
    80001b40:	67c0                	ld	s0,136(a5)
    80001b42:	b7c1                	j	80001b02 <argstr+0x30>
  panic("argraw");
    80001b44:	00004517          	auipc	a0,0x4
    80001b48:	3ec50513          	add	a0,a0,1004 # 80005f30 <kalloc+0x972>
    80001b4c:	e55fe0ef          	jal	800009a0 <panic>
  return -1;
    80001b50:	547d                	li	s0,-1
    80001b52:	bf45                	j	80001b02 <argstr+0x30>
}
    80001b54:	60e2                	ld	ra,24(sp)
    80001b56:	6442                	ld	s0,16(sp)
    80001b58:	64a2                	ld	s1,8(sp)
    80001b5a:	6902                	ld	s2,0(sp)
    80001b5c:	557d                	li	a0,-1
    80001b5e:	6105                	add	sp,sp,32
    80001b60:	8082                	ret

0000000080001b62 <syscall>:
[SYS_close]   sys_close,
};

void
syscall(void)
{
    80001b62:	1101                	add	sp,sp,-32
    80001b64:	ec06                	sd	ra,24(sp)
    80001b66:	e822                	sd	s0,16(sp)
    80001b68:	e426                	sd	s1,8(sp)
    80001b6a:	e04a                	sd	s2,0(sp)
  int num;
  struct proc *p = myproc();
    80001b6c:	1f7000ef          	jal	80002562 <myproc>
  
  num = p->trapframe->a7;
    80001b70:	613c                	ld	a5,64(a0)
  struct proc *p = myproc();
    80001b72:	842a                	mv	s0,a0
  printf("syscall_id: %d\n", num);
    80001b74:	00004517          	auipc	a0,0x4
    80001b78:	3c450513          	add	a0,a0,964 # 80005f38 <kalloc+0x97a>
  num = p->trapframe->a7;
    80001b7c:	77c4                	ld	s1,168(a5)
    80001b7e:	0004891b          	sext.w	s2,s1
  printf("syscall_id: %d\n", num);
    80001b82:	85ca                	mv	a1,s2
    80001b84:	803fe0ef          	jal	80000386 <printf>
  if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
    80001b88:	34fd                	addw	s1,s1,-1
    80001b8a:	47d1                	li	a5,20
    80001b8c:	0297e463          	bltu	a5,s1,80001bb4 <syscall+0x52>
    80001b90:	00391713          	sll	a4,s2,0x3
    80001b94:	00004797          	auipc	a5,0x4
    80001b98:	41c78793          	add	a5,a5,1052 # 80005fb0 <syscalls>
    80001b9c:	97ba                	add	a5,a5,a4
    80001b9e:	639c                	ld	a5,0(a5)
    80001ba0:	cb91                	beqz	a5,80001bb4 <syscall+0x52>
    // Use num to lookup the system call function for num, call it,
    // and store its return value in p->trapframe->a0
    p->trapframe->a0 = syscalls[num]();
    80001ba2:	6020                	ld	s0,64(s0)
    80001ba4:	9782                	jalr	a5
  } else {
    printf("%d %s: unknown sys call %d\n",
            p->pid, p->name, num);
    p->trapframe->a0 = -1;
  }
}
    80001ba6:	60e2                	ld	ra,24(sp)
    p->trapframe->a0 = syscalls[num]();
    80001ba8:	f828                	sd	a0,112(s0)
}
    80001baa:	6442                	ld	s0,16(sp)
    80001bac:	64a2                	ld	s1,8(sp)
    80001bae:	6902                	ld	s2,0(sp)
    80001bb0:	6105                	add	sp,sp,32
    80001bb2:	8082                	ret
    printf("%d %s: unknown sys call %d\n",
    80001bb4:	580c                	lw	a1,48(s0)
    80001bb6:	86ca                	mv	a3,s2
    80001bb8:	0d040613          	add	a2,s0,208
    80001bbc:	00004517          	auipc	a0,0x4
    80001bc0:	38c50513          	add	a0,a0,908 # 80005f48 <kalloc+0x98a>
    80001bc4:	fc2fe0ef          	jal	80000386 <printf>
    p->trapframe->a0 = -1;
    80001bc8:	603c                	ld	a5,64(s0)
}
    80001bca:	60e2                	ld	ra,24(sp)
    80001bcc:	6442                	ld	s0,16(sp)
    p->trapframe->a0 = -1;
    80001bce:	577d                	li	a4,-1
    80001bd0:	fbb8                	sd	a4,112(a5)
}
    80001bd2:	64a2                	ld	s1,8(sp)
    80001bd4:	6902                	ld	s2,0(sp)
    80001bd6:	6105                	add	sp,sp,32
    80001bd8:	8082                	ret

0000000080001bda <sys_fork>:
#include "../../include/memlayout.h"

// 系统调用：fork - 创建新进程
uint64
sys_fork(void)
{
    80001bda:	1141                	add	sp,sp,-16
    80001bdc:	e406                	sd	ra,8(sp)
  return fork();
    80001bde:	52d000ef          	jal	8000290a <fork>
}
    80001be2:	60a2                	ld	ra,8(sp)
    80001be4:	0141                	add	sp,sp,16
    80001be6:	8082                	ret

0000000080001be8 <sys_exit>:

// 系统调用：exit - 退出当前进程
uint64
sys_exit(void)
{
    80001be8:	1101                	add	sp,sp,-32
  int n;
  argint(0, &n);
    80001bea:	006c                	add	a1,sp,12
    80001bec:	4501                	li	a0,0
{
    80001bee:	ec06                	sd	ra,24(sp)
  argint(0, &n);
    80001bf0:	d97ff0ef          	jal	80001986 <argint>
  exit(n);
    80001bf4:	4532                	lw	a0,12(sp)
    80001bf6:	5db000ef          	jal	800029d0 <exit>
  return 0;  // not reached
}
    80001bfa:	60e2                	ld	ra,24(sp)
    80001bfc:	4501                	li	a0,0
    80001bfe:	6105                	add	sp,sp,32
    80001c00:	8082                	ret

0000000080001c02 <sys_wait>:

// 系统调用：wait - 等待子进程退出
uint64
sys_wait(void)
{
    80001c02:	1101                	add	sp,sp,-32
  uint64 p;
  argaddr(0, &p);
    80001c04:	002c                	add	a1,sp,8
    80001c06:	4501                	li	a0,0
{
    80001c08:	ec06                	sd	ra,24(sp)
  argaddr(0, &p);
    80001c0a:	e27ff0ef          	jal	80001a30 <argaddr>
  return wait(p);
    80001c0e:	6522                	ld	a0,8(sp)
    80001c10:	6cf000ef          	jal	80002ade <wait>
}
    80001c14:	60e2                	ld	ra,24(sp)
    80001c16:	6105                	add	sp,sp,32
    80001c18:	8082                	ret

0000000080001c1a <sys_getpid>:

// 系统调用：getpid - 获取当前进程ID
uint64
sys_getpid(void)
{
    80001c1a:	1141                	add	sp,sp,-16
    80001c1c:	e406                	sd	ra,8(sp)
  return myproc()->pid;
    80001c1e:	145000ef          	jal	80002562 <myproc>
}
    80001c22:	60a2                	ld	ra,8(sp)
    80001c24:	5908                	lw	a0,48(a0)
    80001c26:	0141                	add	sp,sp,16
    80001c28:	8082                	ret

0000000080001c2a <sys_sbrk>:

// 系统调用：sbrk - 增加或减少进程的内存空间
uint64
sys_sbrk(void)
{
    80001c2a:	7179                	add	sp,sp,-48
    80001c2c:	f406                	sd	ra,40(sp)
    80001c2e:	f022                	sd	s0,32(sp)
    80001c30:	ec26                	sd	s1,24(sp)
  int addr;
  int n;
  struct proc *p = myproc();
    80001c32:	131000ef          	jal	80002562 <myproc>
    80001c36:	842a                	mv	s0,a0

  argint(0, &n);
    80001c38:	006c                	add	a1,sp,12
    80001c3a:	4501                	li	a0,0
    80001c3c:	d4bff0ef          	jal	80001986 <argint>
  addr = p->sz;
    80001c40:	607c                	ld	a5,192(s0)
  if(n > 0){
    80001c42:	4632                	lw	a2,12(sp)
  addr = p->sz;
    80001c44:	0007871b          	sext.w	a4,a5
  if(n > 0){
    80001c48:	00c05b63          	blez	a2,80001c5e <sys_sbrk+0x34>
    // 懒分配：只增加sz，不实际分配内存
    p->sz += n;
    80001c4c:	963e                	add	a2,a2,a5
    80001c4e:	e070                	sd	a2,192(s0)
  } else if(n < 0){
    // 减少内存：需要释放页
    if((uint64)(addr + n) < addr)
      return -1;
    p->sz = uvmdealloc(p->pagetable, addr, addr + n);
    80001c50:	84ba                	mv	s1,a4
  }
  return addr;
}
    80001c52:	70a2                	ld	ra,40(sp)
    80001c54:	7402                	ld	s0,32(sp)
    80001c56:	8526                	mv	a0,s1
    80001c58:	64e2                	ld	s1,24(sp)
    80001c5a:	6145                	add	sp,sp,48
    80001c5c:	8082                	ret
    p->sz = uvmdealloc(p->pagetable, addr, addr + n);
    80001c5e:	84ba                	mv	s1,a4
  } else if(n < 0){
    80001c60:	da6d                	beqz	a2,80001c52 <sys_sbrk+0x28>
    if((uint64)(addr + n) < addr)
    80001c62:	9e39                	addw	a2,a2,a4
      return -1;
    80001c64:	54fd                	li	s1,-1
    if((uint64)(addr + n) < addr)
    80001c66:	fee666e3          	bltu	a2,a4,80001c52 <sys_sbrk+0x28>
    p->sz = uvmdealloc(p->pagetable, addr, addr + n);
    80001c6a:	6468                	ld	a0,200(s0)
    80001c6c:	85ba                	mv	a1,a4
    80001c6e:	84ba                	mv	s1,a4
    80001c70:	ca8ff0ef          	jal	80001118 <uvmdealloc>
    80001c74:	e068                	sd	a0,192(s0)
}
    80001c76:	70a2                	ld	ra,40(sp)
    80001c78:	7402                	ld	s0,32(sp)
    80001c7a:	8526                	mv	a0,s1
    80001c7c:	64e2                	ld	s1,24(sp)
    80001c7e:	6145                	add	sp,sp,48
    80001c80:	8082                	ret

0000000080001c82 <sys_kill>:

// 系统调用：kill - 杀死指定进程
uint64
sys_kill(void)
{
    80001c82:	7179                	add	sp,sp,-48
  int pid;
  argint(0, &pid);
    80001c84:	006c                	add	a1,sp,12
    80001c86:	4501                	li	a0,0
{
    80001c88:	f022                	sd	s0,32(sp)
    80001c8a:	ec26                	sd	s1,24(sp)
    80001c8c:	f406                	sd	ra,40(sp)
  // 简化实现：查找进程并设置killed标志
  struct proc *p;
  for(p = proc; p < &proc[NPROC]; p++){
    80001c8e:	00005417          	auipc	s0,0x5
    80001c92:	c0240413          	add	s0,s0,-1022 # 80006890 <proc>
  argint(0, &pid);
    80001c96:	cf1ff0ef          	jal	80001986 <argint>
  for(p = proc; p < &proc[NPROC]; p++){
    80001c9a:	0000a497          	auipc	s1,0xa
    80001c9e:	5f648493          	add	s1,s1,1526 # 8000c290 <bcache>
    80001ca2:	a039                	j	80001cb0 <sys_kill+0x2e>
    80001ca4:	16840413          	add	s0,s0,360
    if(p->pid == pid){
      setkilled(p);
      release(&p->lock);
      return 0;
    }
    release(&p->lock);
    80001ca8:	464000ef          	jal	8000210c <release>
  for(p = proc; p < &proc[NPROC]; p++){
    80001cac:	02940563          	beq	s0,s1,80001cd6 <sys_kill+0x54>
    acquire(&p->lock);
    80001cb0:	8522                	mv	a0,s0
    80001cb2:	3b4000ef          	jal	80002066 <acquire>
    if(p->pid == pid){
    80001cb6:	5818                	lw	a4,48(s0)
    80001cb8:	47b2                	lw	a5,12(sp)
    release(&p->lock);
    80001cba:	8522                	mv	a0,s0
    if(p->pid == pid){
    80001cbc:	fef714e3          	bne	a4,a5,80001ca4 <sys_kill+0x22>
      setkilled(p);
    80001cc0:	13c010ef          	jal	80002dfc <setkilled>
      release(&p->lock);
    80001cc4:	8522                	mv	a0,s0
    80001cc6:	446000ef          	jal	8000210c <release>
  }
  return -1;
}
    80001cca:	70a2                	ld	ra,40(sp)
    80001ccc:	7402                	ld	s0,32(sp)
    80001cce:	64e2                	ld	s1,24(sp)
      return 0;
    80001cd0:	4501                	li	a0,0
}
    80001cd2:	6145                	add	sp,sp,48
    80001cd4:	8082                	ret
    80001cd6:	70a2                	ld	ra,40(sp)
    80001cd8:	7402                	ld	s0,32(sp)
    80001cda:	64e2                	ld	s1,24(sp)
  return -1;
    80001cdc:	557d                	li	a0,-1
}
    80001cde:	6145                	add	sp,sp,48
    80001ce0:	8082                	ret

0000000080001ce2 <sys_pause>:
uint64
sys_pause(void)
{
  // 简化实现：什么都不做
  return 0;
}
    80001ce2:	4501                	li	a0,0
    80001ce4:	8082                	ret

0000000080001ce6 <sys_uptime>:
uint64
sys_uptime(void)
{
  extern volatile uint64 ticks;
  return ticks;
}
    80001ce6:	00005517          	auipc	a0,0x5
    80001cea:	9ca53503          	ld	a0,-1590(a0) # 800066b0 <ticks>
    80001cee:	8082                	ret

0000000080001cf0 <sys_exec>:
  return mode == O_WRONLY || mode == O_RDWR;
}

// 系统调用：exec - 执行新程序（暂未实现）
uint64
sys_exec(void)
    80001cf0:	557d                	li	a0,-1
    80001cf2:	8082                	ret

0000000080001cf4 <sys_open>:
}

// 系统调用：open - 打开文件（暂未实现）
uint64
sys_open(void)
{
    80001cf4:	7135                	add	sp,sp,-160
    80001cf6:	e922                	sd	s0,144(sp)
    80001cf8:	ed06                	sd	ra,152(sp)
  char path[128];
  int omode;
  struct proc *p = myproc();
    80001cfa:	069000ef          	jal	80002562 <myproc>
    80001cfe:	842a                	mv	s0,a0

  if(argstr(0, path, sizeof(path)) < 0)
    80001d00:	08000613          	li	a2,128
    80001d04:	080c                	add	a1,sp,16
    80001d06:	4501                	li	a0,0
    80001d08:	dcbff0ef          	jal	80001ad2 <argstr>
    80001d0c:	06054363          	bltz	a0,80001d72 <sys_open+0x7e>
    return -1;
  argint(1, &omode);
    80001d10:	006c                	add	a1,sp,12
    80001d12:	4505                	li	a0,1
    80001d14:	c73ff0ef          	jal	80001986 <argint>
  while(*a && *b){
    80001d18:	01014703          	lbu	a4,16(sp)
    80001d1c:	cb39                	beqz	a4,80001d72 <sys_open+0x7e>
    80001d1e:	00004617          	auipc	a2,0x4
    80001d22:	34260613          	add	a2,a2,834 # 80006060 <syscalls+0xb0>
    80001d26:	081c                	add	a5,sp,16
    80001d28:	06300693          	li	a3,99
    a++;
    80001d2c:	0785                	add	a5,a5,1
    b++;
    80001d2e:	0605                	add	a2,a2,1
    if(*a != *b)
    80001d30:	04e69163          	bne	a3,a4,80001d72 <sys_open+0x7e>
  while(*a && *b){
    80001d34:	0007c703          	lbu	a4,0(a5)
  return *a == *b;
    80001d38:	00064683          	lbu	a3,0(a2)
  while(*a && *b){
    80001d3c:	c311                	beqz	a4,80001d40 <sys_open+0x4c>
    80001d3e:	f6fd                	bnez	a3,80001d2c <sys_open+0x38>

  struct file *target = 0;
  if(str_eq(path, "console")){
    80001d40:	02e69963          	bne	a3,a4,80001d72 <sys_open+0x7e>
    if(omode == O_RDONLY)
    80001d44:	47b2                	lw	a5,12(sp)
      target = &console_file_ro;
    80001d46:	00005597          	auipc	a1,0x5
    80001d4a:	a4258593          	add	a1,a1,-1470 # 80006788 <console_file_ro>
    if(omode == O_RDONLY)
    80001d4e:	cb81                	beqz	a5,80001d5e <sys_open+0x6a>
    else if(omode == O_WRONLY)
      target = &console_file_wo;
    else if(omode == O_RDWR)
    80001d50:	4709                	li	a4,2
      target = &console_file_wo;
    80001d52:	00005597          	auipc	a1,0x5
    80001d56:	a0e58593          	add	a1,a1,-1522 # 80006760 <console_file_wo>
    else if(omode == O_RDWR)
    80001d5a:	02e78b63          	beq	a5,a4,80001d90 <sys_open+0x9c>
  for(int fd = 0; fd < NOFILE; fd++){
    80001d5e:	0e840713          	add	a4,s0,232
    80001d62:	4781                	li	a5,0
    80001d64:	4641                	li	a2,16
    if(p->ofile[fd] == 0){
    80001d66:	6314                	ld	a3,0(a4)
  for(int fd = 0; fd < NOFILE; fd++){
    80001d68:	0721                	add	a4,a4,8
    if(p->ofile[fd] == 0){
    80001d6a:	ca89                	beqz	a3,80001d7c <sys_open+0x88>
  for(int fd = 0; fd < NOFILE; fd++){
    80001d6c:	2785                	addw	a5,a5,1
    80001d6e:	fec79ce3          	bne	a5,a2,80001d66 <sys_open+0x72>

  int fd = fdalloc(p, target);
  if(fd < 0)
    return -1;
  return fd;
}
    80001d72:	60ea                	ld	ra,152(sp)
    80001d74:	644a                	ld	s0,144(sp)
    return -1;
    80001d76:	557d                	li	a0,-1
}
    80001d78:	610d                	add	sp,sp,160
    80001d7a:	8082                	ret
      p->ofile[fd] = f;
    80001d7c:	01c78713          	add	a4,a5,28
    80001d80:	070e                	sll	a4,a4,0x3
    80001d82:	943a                	add	s0,s0,a4
}
    80001d84:	60ea                	ld	ra,152(sp)
      p->ofile[fd] = f;
    80001d86:	e40c                	sd	a1,8(s0)
}
    80001d88:	644a                	ld	s0,144(sp)
  return fd;
    80001d8a:	853e                	mv	a0,a5
}
    80001d8c:	610d                	add	sp,sp,160
    80001d8e:	8082                	ret
      target = &console_file_rw;
    80001d90:	00005597          	auipc	a1,0x5
    80001d94:	a2058593          	add	a1,a1,-1504 # 800067b0 <console_file_rw>
    80001d98:	b7d9                	j	80001d5e <sys_open+0x6a>

0000000080001d9a <sys_read>:

// 系统调用：read - 读取文件（暂未实现）
uint64
sys_read(void)
{
    80001d9a:	7135                	add	sp,sp,-160
    80001d9c:	ed06                	sd	ra,152(sp)
    80001d9e:	f8d2                	sd	s4,112(sp)
    80001da0:	e922                	sd	s0,144(sp)
    80001da2:	e526                	sd	s1,136(sp)
    80001da4:	e14a                	sd	s2,128(sp)
    80001da6:	fcce                	sd	s3,120(sp)
    80001da8:	f4d6                	sd	s5,104(sp)
    80001daa:	f0da                	sd	s6,96(sp)
    80001dac:	ecde                	sd	s7,88(sp)
  int fd;
  uint64 dst;
  int n;
  struct proc *p = myproc();
    80001dae:	7b4000ef          	jal	80002562 <myproc>

  argint(0, &fd);
    80001db2:	858a                	mv	a1,sp
  struct proc *p = myproc();
    80001db4:	8a2a                	mv	s4,a0
  argint(0, &fd);
    80001db6:	4501                	li	a0,0
    80001db8:	bcfff0ef          	jal	80001986 <argint>
  argaddr(1, &dst);
    80001dbc:	002c                	add	a1,sp,8
    80001dbe:	4505                	li	a0,1
    80001dc0:	c71ff0ef          	jal	80001a30 <argaddr>
  argint(2, &n);
    80001dc4:	004c                	add	a1,sp,4
    80001dc6:	4509                	li	a0,2
    80001dc8:	bbfff0ef          	jal	80001986 <argint>

  if(n < 0)
    80001dcc:	4792                	lw	a5,4(sp)
    80001dce:	0a07c363          	bltz	a5,80001e74 <sys_read+0xda>
    return -1;
  if(n == 0)
    return 0;
    80001dd2:	4401                	li	s0,0
  if(n == 0)
    80001dd4:	c3cd                	beqz	a5,80001e76 <sys_read+0xdc>

  if(!is_console_read_fd(p, fd))
    80001dd6:	4902                	lw	s2,0(sp)
  if(fd < 0 || fd >= NOFILE)
    80001dd8:	47bd                	li	a5,15
    80001dda:	0927ed63          	bltu	a5,s2,80001e74 <sys_read+0xda>
  struct file *f = p->ofile[fd];
    80001dde:	01c90793          	add	a5,s2,28
    80001de2:	078e                	sll	a5,a5,0x3
    80001de4:	97d2                	add	a5,a5,s4
    80001de6:	679c                	ld	a5,8(a5)
  if(f == 0)
    80001de8:	c7f5                	beqz	a5,80001ed4 <sys_read+0x13a>
  if(f == &console_file_ro)
    80001dea:	00005717          	auipc	a4,0x5
    80001dee:	99e70713          	add	a4,a4,-1634 # 80006788 <console_file_ro>
    80001df2:	00005697          	auipc	a3,0x5
    80001df6:	96e68693          	add	a3,a3,-1682 # 80006760 <console_file_wo>
    80001dfa:	00e78a63          	beq	a5,a4,80001e0e <sys_read+0x74>
  if(f == &console_file_wo)
    80001dfe:	06d78b63          	beq	a5,a3,80001e74 <sys_read+0xda>
  if(f == &console_file_rw)
    80001e02:	00005717          	auipc	a4,0x5
    80001e06:	9ae70713          	add	a4,a4,-1618 # 800067b0 <console_file_rw>
    80001e0a:	06e79563          	bne	a5,a4,80001e74 <sys_read+0xda>
    80001e0e:	4405                	li	s0,1
    80001e10:	4901                	li	s2,0
  int chunk_len = 0;
  char buf[64];

  while(copied < n){
    char c = (char)uart_getc();
    if(c == '\r')
    80001e12:	4ab5                	li	s5,13
      c = '\n';
    buf[chunk_len++] = c;
    copied++;

    if(chunk_len == sizeof(buf) || c == '\n' || copied == n){
    80001e14:	03f00b93          	li	s7,63
      if(copyout(p->pagetable, dst + copied - chunk_len, buf, chunk_len) < 0)
        return -1;
      chunk_len = 0;
      if(c == '\n')
    80001e18:	4b29                	li	s6,10
    80001e1a:	a00d                	j	80001e3c <sys_read+0xa2>
    buf[chunk_len++] = c;
    80001e1c:	978a                	add	a5,a5,sp
    80001e1e:	fc978023          	sb	s1,-64(a5)
    if(chunk_len == sizeof(buf) || c == '\n' || copied == n){
    80001e22:	09790963          	beq	s2,s7,80001eb4 <sys_read+0x11a>
    80001e26:	03648c63          	beq	s1,s6,80001e5e <sys_read+0xc4>
    80001e2a:	4792                	lw	a5,4(sp)
    buf[chunk_len++] = c;
    80001e2c:	8936                	mv	s2,a3
    if(chunk_len == sizeof(buf) || c == '\n' || copied == n){
    80001e2e:	07378063          	beq	a5,s3,80001e8e <sys_read+0xf4>
  while(copied < n){
    80001e32:	0405                	add	s0,s0,1
    80001e34:	fff4071b          	addw	a4,s0,-1
    80001e38:	06f75c63          	bge	a4,a5,80001eb0 <sys_read+0x116>
    char c = (char)uart_getc();
    80001e3c:	a98fe0ef          	jal	800000d4 <uart_getc>
    80001e40:	0ff57493          	zext.b	s1,a0
    buf[chunk_len++] = c;
    80001e44:	0019069b          	addw	a3,s2,1
    copied++;
    80001e48:	0004099b          	sext.w	s3,s0
    buf[chunk_len++] = c;
    80001e4c:	05090793          	add	a5,s2,80
    if(c == '\r')
    80001e50:	fd5496e3          	bne	s1,s5,80001e1c <sys_read+0x82>
    buf[chunk_len++] = c;
    80001e54:	00278933          	add	s2,a5,sp
    80001e58:	47a9                	li	a5,10
    80001e5a:	fcf90023          	sb	a5,-64(s2)
      if(copyout(p->pagetable, dst + copied - chunk_len, buf, chunk_len) < 0)
    80001e5e:	65a2                	ld	a1,8(sp)
    80001e60:	0c8a3503          	ld	a0,200(s4) # 10c8 <_entry-0x7fffef38>
    80001e64:	0810                	add	a2,sp,16
    80001e66:	95ce                	add	a1,a1,s3
    80001e68:	8d95                	sub	a1,a1,a3
    80001e6a:	844e                	mv	s0,s3
    80001e6c:	56b000ef          	jal	80002bd6 <copyout>
    80001e70:	00055363          	bgez	a0,80001e76 <sys_read+0xdc>
    return -1;
    80001e74:	547d                	li	s0,-1
        break;
    }
  }

  return copied;
}
    80001e76:	60ea                	ld	ra,152(sp)
    80001e78:	8522                	mv	a0,s0
    80001e7a:	644a                	ld	s0,144(sp)
    80001e7c:	64aa                	ld	s1,136(sp)
    80001e7e:	690a                	ld	s2,128(sp)
    80001e80:	79e6                	ld	s3,120(sp)
    80001e82:	7a46                	ld	s4,112(sp)
    80001e84:	7aa6                	ld	s5,104(sp)
    80001e86:	7b06                	ld	s6,96(sp)
    80001e88:	6be6                	ld	s7,88(sp)
    80001e8a:	610d                	add	sp,sp,160
    80001e8c:	8082                	ret
      if(copyout(p->pagetable, dst + copied - chunk_len, buf, chunk_len) < 0)
    80001e8e:	65a2                	ld	a1,8(sp)
    80001e90:	0c8a3503          	ld	a0,200(s4)
    80001e94:	0810                	add	a2,sp,16
    80001e96:	95a2                	add	a1,a1,s0
    80001e98:	8d95                	sub	a1,a1,a3
    80001e9a:	53d000ef          	jal	80002bd6 <copyout>
    80001e9e:	fc054be3          	bltz	a0,80001e74 <sys_read+0xda>
  while(copied < n){
    80001ea2:	4792                	lw	a5,4(sp)
    80001ea4:	0405                	add	s0,s0,1
    80001ea6:	fff4071b          	addw	a4,s0,-1
      chunk_len = 0;
    80001eaa:	4901                	li	s2,0
  while(copied < n){
    80001eac:	f8f748e3          	blt	a4,a5,80001e3c <sys_read+0xa2>
      if(copyout(p->pagetable, dst + copied - chunk_len, buf, chunk_len) < 0)
    80001eb0:	844e                	mv	s0,s3
  return copied;
    80001eb2:	b7d1                	j	80001e76 <sys_read+0xdc>
      if(copyout(p->pagetable, dst + copied - chunk_len, buf, chunk_len) < 0)
    80001eb4:	65a2                	ld	a1,8(sp)
    80001eb6:	0c8a3503          	ld	a0,200(s4)
    80001eba:	04000693          	li	a3,64
    80001ebe:	fc058593          	add	a1,a1,-64
    80001ec2:	0810                	add	a2,sp,16
    80001ec4:	95a2                	add	a1,a1,s0
    80001ec6:	511000ef          	jal	80002bd6 <copyout>
    80001eca:	fa0545e3          	bltz	a0,80001e74 <sys_read+0xda>
      if(c == '\n')
    80001ece:	fd649ae3          	bne	s1,s6,80001ea2 <sys_read+0x108>
    80001ed2:	b755                	j	80001e76 <sys_read+0xdc>
  if(!is_console_read_fd(p, fd))
    80001ed4:	fa0910e3          	bnez	s2,80001e74 <sys_read+0xda>
    80001ed8:	4405                	li	s0,1
    80001eda:	bf25                	j	80001e12 <sys_read+0x78>

0000000080001edc <sys_write>:

// 系统调用：write 
uint64
sys_write(void)
{
    80001edc:	7155                	add	sp,sp,-208
    80001ede:	e586                	sd	ra,200(sp)
    80001ee0:	f152                	sd	s4,160(sp)
    80001ee2:	e1a2                	sd	s0,192(sp)
    80001ee4:	fd26                	sd	s1,184(sp)
    80001ee6:	f94a                	sd	s2,176(sp)
    80001ee8:	f54e                	sd	s3,168(sp)
    80001eea:	ed56                	sd	s5,152(sp)
  int fd;
  uint64 src;
  int n;
  struct proc *p = myproc();
    80001eec:	676000ef          	jal	80002562 <myproc>

  argint(0, &fd);
    80001ef0:	858a                	mv	a1,sp
  struct proc *p = myproc();
    80001ef2:	8a2a                	mv	s4,a0
  argint(0, &fd);
    80001ef4:	4501                	li	a0,0
    80001ef6:	a91ff0ef          	jal	80001986 <argint>
  argaddr(1, &src);
    80001efa:	002c                	add	a1,sp,8
    80001efc:	4505                	li	a0,1
    80001efe:	b33ff0ef          	jal	80001a30 <argaddr>
  argint(2, &n);
    80001f02:	004c                	add	a1,sp,4
    80001f04:	4509                	li	a0,2
    80001f06:	a81ff0ef          	jal	80001986 <argint>

  if(n < 0)
    80001f0a:	4792                	lw	a5,4(sp)
    80001f0c:	0807c963          	bltz	a5,80001f9e <sys_write+0xc2>
    return -1;

  if(!is_console_write_fd(p, fd))
    80001f10:	4702                	lw	a4,0(sp)
  if(fd < 0 || fd >= NOFILE)
    80001f12:	46bd                	li	a3,15
    80001f14:	0007061b          	sext.w	a2,a4
    80001f18:	08e6e363          	bltu	a3,a4,80001f9e <sys_write+0xc2>
  struct file *f = p->ofile[fd];
    80001f1c:	0771                	add	a4,a4,28
    80001f1e:	070e                	sll	a4,a4,0x3
    80001f20:	9752                	add	a4,a4,s4
    80001f22:	6718                	ld	a4,8(a4)
  if(f == 0)
    80001f24:	cb2d                	beqz	a4,80001f96 <sys_write+0xba>
  if(f == &console_file_ro)
    80001f26:	00005697          	auipc	a3,0x5
    80001f2a:	86268693          	add	a3,a3,-1950 # 80006788 <console_file_ro>
    80001f2e:	00005617          	auipc	a2,0x5
    80001f32:	83260613          	add	a2,a2,-1998 # 80006760 <console_file_wo>
    80001f36:	06d70463          	beq	a4,a3,80001f9e <sys_write+0xc2>
  if(f == &console_file_wo)
    80001f3a:	00c70863          	beq	a4,a2,80001f4a <sys_write+0x6e>
  if(f == &console_file_rw)
    80001f3e:	00005697          	auipc	a3,0x5
    80001f42:	87268693          	add	a3,a3,-1934 # 800067b0 <console_file_rw>
    80001f46:	04d71c63          	bne	a4,a3,80001f9e <sys_write+0xc2>
    return -1;

  int total = 0;
  char buf[128];

  while(total < n){
    80001f4a:	4901                	li	s2,0
    int m = n - total;
    if(m > (int)sizeof(buf))
    80001f4c:	08000a93          	li	s5,128
  while(total < n){
    80001f50:	4501                	li	a0,0
    80001f52:	c7b9                	beqz	a5,80001fa0 <sys_write+0xc4>
    if(m > (int)sizeof(buf))
    80001f54:	412789bb          	subw	s3,a5,s2
    80001f58:	013ad463          	bge	s5,s3,80001f60 <sys_write+0x84>
    80001f5c:	08000993          	li	s3,128
      m = sizeof(buf);
    if(copyin(p->pagetable, buf, src + total, m) < 0)
    80001f60:	6622                	ld	a2,8(sp)
    80001f62:	0c8a3503          	ld	a0,200(s4)
    80001f66:	86ce                	mv	a3,s3
    80001f68:	964a                	add	a2,a2,s2
    80001f6a:	080c                	add	a1,sp,16
    80001f6c:	4b5000ef          	jal	80002c20 <copyin>
    80001f70:	02054763          	bltz	a0,80001f9e <sys_write+0xc2>
    80001f74:	0800                	add	s0,sp,16
    80001f76:	013404b3          	add	s1,s0,s3
      return -1;
    for(int i = 0; i < m; i++){
      console_putc(buf[i]);
    80001f7a:	00044503          	lbu	a0,0(s0)
    for(int i = 0; i < m; i++){
    80001f7e:	0405                	add	s0,s0,1
      console_putc(buf[i]);
    80001f80:	9befe0ef          	jal	8000013e <console_putc>
    for(int i = 0; i < m; i++){
    80001f84:	fe849be3          	bne	s1,s0,80001f7a <sys_write+0x9e>
  while(total < n){
    80001f88:	4792                	lw	a5,4(sp)
    }
    total += m;
    80001f8a:	0129893b          	addw	s2,s3,s2
  while(total < n){
    80001f8e:	fcf943e3          	blt	s2,a5,80001f54 <sys_write+0x78>
  }
  return total;
    80001f92:	854a                	mv	a0,s2
    80001f94:	a031                	j	80001fa0 <sys_write+0xc4>
  if(!is_console_write_fd(p, fd))
    80001f96:	367d                	addw	a2,a2,-1
    80001f98:	4705                	li	a4,1
    80001f9a:	fac778e3          	bgeu	a4,a2,80001f4a <sys_write+0x6e>
    return -1;
    80001f9e:	557d                	li	a0,-1
}
    80001fa0:	60ae                	ld	ra,200(sp)
    80001fa2:	640e                	ld	s0,192(sp)
    80001fa4:	74ea                	ld	s1,184(sp)
    80001fa6:	794a                	ld	s2,176(sp)
    80001fa8:	79aa                	ld	s3,168(sp)
    80001faa:	7a0a                	ld	s4,160(sp)
    80001fac:	6aea                	ld	s5,152(sp)
    80001fae:	6169                	add	sp,sp,208
    80001fb0:	8082                	ret

0000000080001fb2 <sys_close>:

// 系统调用：close - 关闭文件（暂未实现）
uint64
sys_close(void)
{
    80001fb2:	1101                	add	sp,sp,-32
    80001fb4:	ec06                	sd	ra,24(sp)
    80001fb6:	e822                	sd	s0,16(sp)
  int fd;
  struct proc *p = myproc();
    80001fb8:	5aa000ef          	jal	80002562 <myproc>
    80001fbc:	842a                	mv	s0,a0

  argint(0, &fd);
    80001fbe:	006c                	add	a1,sp,12
    80001fc0:	4501                	li	a0,0
    80001fc2:	9c5ff0ef          	jal	80001986 <argint>
  if(fd < 0 || fd >= NOFILE)
    80001fc6:	47b2                	lw	a5,12(sp)
    80001fc8:	473d                	li	a4,15
    80001fca:	557d                	li	a0,-1
    80001fcc:	00f76863          	bltu	a4,a5,80001fdc <sys_close+0x2a>
    return -1;

  p->ofile[fd] = 0;
    80001fd0:	07f1                	add	a5,a5,28
    80001fd2:	078e                	sll	a5,a5,0x3
    80001fd4:	97a2                	add	a5,a5,s0
    80001fd6:	0007b423          	sd	zero,8(a5)
  return 0;
    80001fda:	4501                	li	a0,0
}
    80001fdc:	60e2                	ld	ra,24(sp)
    80001fde:	6442                	ld	s0,16(sp)
    80001fe0:	6105                	add	sp,sp,32
    80001fe2:	8082                	ret

0000000080001fe4 <sys_fstat>:

// 系统调用：fstat - 获取文件状态（暂未实现）
uint64
sys_fstat(void)
    80001fe4:	557d                	li	a0,-1
    80001fe6:	8082                	ret

0000000080001fe8 <sys_link>:
  return -1;
}

// 系统调用：link - 创建硬链接（暂未实现）
uint64
sys_link(void)
    80001fe8:	557d                	li	a0,-1
    80001fea:	8082                	ret

0000000080001fec <sys_unlink>:
  return -1;
}

// 系统调用：unlink - 删除文件（暂未实现）
uint64
sys_unlink(void)
    80001fec:	557d                	li	a0,-1
    80001fee:	8082                	ret

0000000080001ff0 <sys_mkdir>:
  return -1;
}

// 系统调用：mkdir - 创建目录（暂未实现）
uint64
sys_mkdir(void)
    80001ff0:	557d                	li	a0,-1
    80001ff2:	8082                	ret

0000000080001ff4 <sys_mknod>:
  return -1;
}

// 系统调用：mknod - 创建设备节点（暂未实现）
uint64
sys_mknod(void)
    80001ff4:	557d                	li	a0,-1
    80001ff6:	8082                	ret

0000000080001ff8 <sys_chdir>:
  return -1;
}

// 系统调用：chdir - 改变工作目录（暂未实现）
uint64
sys_chdir(void)
    80001ff8:	557d                	li	a0,-1
    80001ffa:	8082                	ret

0000000080001ffc <sys_dup>:
  return -1;
}

// 系统调用：dup - 复制文件描述符（暂未实现）
uint64
sys_dup(void)
    80001ffc:	557d                	li	a0,-1
    80001ffe:	8082                	ret

0000000080002000 <sys_pipe>:
uint64
sys_pipe(void)
{
  // 暂未实现
  return -1;
}
    80002000:	557d                	li	a0,-1
    80002002:	8082                	ret

0000000080002004 <initlock>:
#include "spinlock.h"
#include "../../include/riscv.h"
#include "../boot/printf.h"

// 初始化锁
void initlock(spinlock *lk, char *name) {
    80002004:	1141                	add	sp,sp,-16
    80002006:	e422                	sd	s0,8(sp)
    80002008:	0800                	add	s0,sp,16
  lk->locked = 0;
    8000200a:	00052023          	sw	zero,0(a0)
  lk->name = name;
    8000200e:	e50c                	sd	a1,8(a0)
  lk->cpu = 0;
    80002010:	00052823          	sw	zero,16(a0)
  lk->count = 0;
    80002014:	00052a23          	sw	zero,20(a0)
}
    80002018:	6422                	ld	s0,8(sp)
    8000201a:	0141                	add	sp,sp,16
    8000201c:	8082                	ret

000000008000201e <holding>:
  // 恢复中断状态
  pop_off();
}

// 检查是否持有锁
int holding(spinlock *lk) {
    8000201e:	1141                	add	sp,sp,-16
    80002020:	e422                	sd	s0,8(sp)
    80002022:	0800                	add	s0,sp,16
  return lk->locked;
    80002024:	4108                	lw	a0,0(a0)
}
    80002026:	6422                	ld	s0,8(sp)
    80002028:	0141                	add	sp,sp,16
    8000202a:	8082                	ret

000000008000202c <push_off>:
// 中断嵌套计数器（单核简化版）
static int ncli = 0;           // 嵌套深度
static int intena = 0;          // 进入临界区前的中断状态

// 关闭中断并增加嵌套计数
void push_off(void) {
    8000202c:	1141                	add	sp,sp,-16
    8000202e:	e422                	sd	s0,8(sp)
    80002030:	0800                	add	s0,sp,16

static inline uint64
r_sstatus()
{
  uint64 x;
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80002032:	10002773          	csrr	a4,sstatus
    80002036:	100027f3          	csrr	a5,sstatus

// disable device interrupts
static inline void
intr_off()
{
  w_sstatus(r_sstatus() & ~SSTATUS_SIE);
    8000203a:	9bf5                	and	a5,a5,-3
  asm volatile("csrw sstatus, %0" : : "r" (x));
    8000203c:	10079073          	csrw	sstatus,a5
  int old = intr_get();
  intr_off();
  
  // 记录第一次进入时的中断状态
  if(ncli == 0) {
    80002040:	00004797          	auipc	a5,0x4
    80002044:	67c7a783          	lw	a5,1660(a5) # 800066bc <ncli>
    80002048:	e799                	bnez	a5,80002056 <push_off+0x2a>
// are device interrupts enabled?
static inline int
intr_get()
{
  uint64 x = r_sstatus();
  return (x & SSTATUS_SIE) != 0;
    8000204a:	8305                	srl	a4,a4,0x1
    8000204c:	8b05                	and	a4,a4,1
    intena = old;
    8000204e:	00004697          	auipc	a3,0x4
    80002052:	66e6a523          	sw	a4,1642(a3) # 800066b8 <intena>
  }
  ncli++;
    80002056:	2785                	addw	a5,a5,1
    80002058:	00004717          	auipc	a4,0x4
    8000205c:	66f72223          	sw	a5,1636(a4) # 800066bc <ncli>
}
    80002060:	6422                	ld	s0,8(sp)
    80002062:	0141                	add	sp,sp,16
    80002064:	8082                	ret

0000000080002066 <acquire>:
void acquire(spinlock *lk) {
    80002066:	1101                	add	sp,sp,-32
    80002068:	ec06                	sd	ra,24(sp)
    8000206a:	e822                	sd	s0,16(sp)
    8000206c:	e426                	sd	s1,8(sp)
    8000206e:	1000                	add	s0,sp,32
    80002070:	84aa                	mv	s1,a0
  push_off();
    80002072:	fbbff0ef          	jal	8000202c <push_off>
  if(lk->count > 0) {
    80002076:	48dc                	lw	a5,20(s1)
  while(__sync_lock_test_and_set(&lk->locked, 1) != 0) {
    80002078:	4705                	li	a4,1
  if(lk->count > 0) {
    8000207a:	02f04263          	bgtz	a5,8000209e <acquire+0x38>
  while(__sync_lock_test_and_set(&lk->locked, 1) != 0) {
    8000207e:	87ba                	mv	a5,a4
    80002080:	0cf4a7af          	amoswap.w.aq	a5,a5,(s1)
    80002084:	2781                	sext.w	a5,a5
    80002086:	ffe5                	bnez	a5,8000207e <acquire+0x18>
  __sync_synchronize();
    80002088:	0ff0000f          	fence
// this core's hartid (core number), the index into cpus[].
static inline uint64
r_tp()
{
  uint64 x;
  asm volatile("mv %0, tp" : "=r" (x) );
    8000208c:	8792                	mv	a5,tp
  lk->cpu = r_tp();
    8000208e:	c89c                	sw	a5,16(s1)
    80002090:	4785                	li	a5,1
    lk->count++;
    80002092:	c8dc                	sw	a5,20(s1)
}
    80002094:	60e2                	ld	ra,24(sp)
    80002096:	6442                	ld	s0,16(sp)
    80002098:	64a2                	ld	s1,8(sp)
    8000209a:	6105                	add	sp,sp,32
    8000209c:	8082                	ret
    lk->count++;
    8000209e:	2785                	addw	a5,a5,1
    return;
    800020a0:	bfcd                	j	80002092 <acquire+0x2c>

00000000800020a2 <pop_off>:

// 减少嵌套计数，如果为0则恢复中断
void pop_off(void) {
    800020a2:	1141                	add	sp,sp,-16
    800020a4:	e406                	sd	ra,8(sp)
    800020a6:	e022                	sd	s0,0(sp)
    800020a8:	0800                	add	s0,sp,16
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    800020aa:	100027f3          	csrr	a5,sstatus
  return (x & SSTATUS_SIE) != 0;
    800020ae:	8b89                	and	a5,a5,2
  // 不允许中断状态
  if(intr_get()) {
    800020b0:	e3a1                	bnez	a5,800020f0 <pop_off+0x4e>
    panic("pop_off - interruptible");
  }
  
  ncli--;
    800020b2:	00004717          	auipc	a4,0x4
    800020b6:	60a70713          	add	a4,a4,1546 # 800066bc <ncli>
    800020ba:	431c                	lw	a5,0(a4)
    800020bc:	37fd                	addw	a5,a5,-1
    800020be:	0007869b          	sext.w	a3,a5
    800020c2:	c31c                	sw	a5,0(a4)
  
  // 嵌套计数不能为负
  if(ncli < 0) {
    800020c4:	0206cd63          	bltz	a3,800020fe <pop_off+0x5c>
    panic("pop_off");
  }
  
  // 如果回到了最外层，恢复中断状态
  if(ncli == 0 && intena) {
    800020c8:	00004797          	auipc	a5,0x4
    800020cc:	5f47a783          	lw	a5,1524(a5) # 800066bc <ncli>
    800020d0:	ef81                	bnez	a5,800020e8 <pop_off+0x46>
    800020d2:	00004797          	auipc	a5,0x4
    800020d6:	5e67a783          	lw	a5,1510(a5) # 800066b8 <intena>
    800020da:	c799                	beqz	a5,800020e8 <pop_off+0x46>
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    800020dc:	100027f3          	csrr	a5,sstatus
  w_sstatus(r_sstatus() | SSTATUS_SIE);
    800020e0:	0027e793          	or	a5,a5,2
  asm volatile("csrw sstatus, %0" : : "r" (x));
    800020e4:	10079073          	csrw	sstatus,a5
    intr_on();
  }
}
    800020e8:	60a2                	ld	ra,8(sp)
    800020ea:	6402                	ld	s0,0(sp)
    800020ec:	0141                	add	sp,sp,16
    800020ee:	8082                	ret
    panic("pop_off - interruptible");
    800020f0:	00004517          	auipc	a0,0x4
    800020f4:	f7850513          	add	a0,a0,-136 # 80006068 <syscalls+0xb8>
    800020f8:	8a9fe0ef          	jal	800009a0 <panic>
    800020fc:	bf5d                	j	800020b2 <pop_off+0x10>
    panic("pop_off");
    800020fe:	00004517          	auipc	a0,0x4
    80002102:	f8250513          	add	a0,a0,-126 # 80006080 <syscalls+0xd0>
    80002106:	89bfe0ef          	jal	800009a0 <panic>
    8000210a:	bf7d                	j	800020c8 <pop_off+0x26>

000000008000210c <release>:
void release(spinlock *lk) {
    8000210c:	1141                	add	sp,sp,-16
    8000210e:	e406                	sd	ra,8(sp)
    80002110:	e022                	sd	s0,0(sp)
    80002112:	0800                	add	s0,sp,16
  lk->count--;
    80002114:	495c                	lw	a5,20(a0)
    80002116:	37fd                	addw	a5,a5,-1
    80002118:	0007871b          	sext.w	a4,a5
    8000211c:	c95c                	sw	a5,20(a0)
   if(lk->count == 0) {
    8000211e:	c719                	beqz	a4,8000212c <release+0x20>
  pop_off();
    80002120:	f83ff0ef          	jal	800020a2 <pop_off>
}
    80002124:	60a2                	ld	ra,8(sp)
    80002126:	6402                	ld	s0,0(sp)
    80002128:	0141                	add	sp,sp,16
    8000212a:	8082                	ret
    lk->cpu = 0;
    8000212c:	00052823          	sw	zero,16(a0)
  __sync_synchronize();
    80002130:	0ff0000f          	fence
  __sync_lock_release(&lk->locked);
    80002134:	0f50000f          	fence	iorw,ow
    80002138:	0805202f          	amoswap.w	zero,zero,(a0)
    8000213c:	b7d5                	j	80002120 <release+0x14>

000000008000213e <forkret>:
  // 释放用户地址空间的所有内存和页表结构
  uvmfree(pagetable, sz);
}

// forkret是fork进程第一次被scheduler调度时执行的地方
void forkret(void) {
    8000213e:	1141                	add	sp,sp,-16
    80002140:	e022                	sd	s0,0(sp)



// 获取当前CPU的进程结构体指针
struct proc* myproc(void) {
  return cpus[0].proc;
    80002142:	00004417          	auipc	s0,0x4
    80002146:	69643403          	ld	s0,1686(s0) # 800067d8 <cpus>
  release(&p->lock);
    8000214a:	8522                	mv	a0,s0
void forkret(void) {
    8000214c:	e406                	sd	ra,8(sp)
  release(&p->lock);
    8000214e:	fbfff0ef          	jal	8000210c <release>
  prepare_return();
    80002152:	df6ff0ef          	jal	80001748 <prepare_return>
  uint64 trampoline_userret = TRAMPOLINE + (userret - trampoline);
    80002156:	04000737          	lui	a4,0x4000
  uint64 satp = MAKE_SATP(p->pagetable);
    8000215a:	6468                	ld	a0,200(s0)
  uint64 trampoline_userret = TRAMPOLINE + (userret - trampoline);
    8000215c:	00016797          	auipc	a5,0x16
    80002160:	f4078793          	add	a5,a5,-192 # 8001809c <userret>
    80002164:	00016697          	auipc	a3,0x16
    80002168:	e9c68693          	add	a3,a3,-356 # 80018000 <trampoline>
    8000216c:	177d                	add	a4,a4,-1 # 3ffffff <_entry-0x7c000001>
}
    8000216e:	6402                	ld	s0,0(sp)
  uint64 trampoline_userret = TRAMPOLINE + (userret - trampoline);
    80002170:	0732                	sll	a4,a4,0xc
    80002172:	8f95                	sub	a5,a5,a3
}
    80002174:	60a2                	ld	ra,8(sp)
  uint64 trampoline_userret = TRAMPOLINE + (userret - trampoline);
    80002176:	97ba                	add	a5,a5,a4
  ((void (*)(uint64))trampoline_userret)(satp);
    80002178:	577d                	li	a4,-1
  uint64 satp = MAKE_SATP(p->pagetable);
    8000217a:	8131                	srl	a0,a0,0xc
  ((void (*)(uint64))trampoline_userret)(satp);
    8000217c:	177e                	sll	a4,a4,0x3f
    8000217e:	8d59                	or	a0,a0,a4
}
    80002180:	0141                	add	sp,sp,16
  ((void (*)(uint64))trampoline_userret)(satp);
    80002182:	8782                	jr	a5

0000000080002184 <proc_mapstacks>:
void proc_mapstacks(pagetable_t kpgtbl) {
    80002184:	715d                	add	sp,sp,-80
    uint64 va = KSTACK((int) (p - proc));
    80002186:	020007b7          	lui	a5,0x2000
void proc_mapstacks(pagetable_t kpgtbl) {
    8000218a:	f44e                	sd	s3,40(sp)
    uint64 va = KSTACK((int) (p - proc));
    8000218c:	17fd                	add	a5,a5,-1 # 1ffffff <_entry-0x7e000001>
  for(p = proc; p < &proc[NPROC]; p++) {
    8000218e:	00004997          	auipc	s3,0x4
    80002192:	70298993          	add	s3,s3,1794 # 80006890 <proc>
void proc_mapstacks(pagetable_t kpgtbl) {
    80002196:	e0a2                	sd	s0,64(sp)
    80002198:	fc26                	sd	s1,56(sp)
    8000219a:	f84a                	sd	s2,48(sp)
    8000219c:	f052                	sd	s4,32(sp)
    8000219e:	ec56                	sd	s5,24(sp)
    800021a0:	e85a                	sd	s6,16(sp)
    800021a2:	e486                	sd	ra,72(sp)
    800021a4:	892a                	mv	s2,a0
  for(p = proc; p < &proc[NPROC]; p++) {
    800021a6:	844e                	mv	s0,s3
    800021a8:	00003a97          	auipc	s5,0x3
    800021ac:	468aba83          	ld	s5,1128(s5) # 80005610 <kalloc+0x52>
    800021b0:	0000aa17          	auipc	s4,0xa
    800021b4:	0e0a0a13          	add	s4,s4,224 # 8000c290 <bcache>
      panic("kalloc");
    800021b8:	00004b17          	auipc	s6,0x4
    800021bc:	ed0b0b13          	add	s6,s6,-304 # 80006088 <syscalls+0xd8>
    uint64 va = KSTACK((int) (p - proc));
    800021c0:	00d79493          	sll	s1,a5,0xd
    800021c4:	a01d                	j	800021ea <proc_mapstacks+0x66>
    800021c6:	413405b3          	sub	a1,s0,s3
    800021ca:	858d                	sra	a1,a1,0x3
    800021cc:	035585b3          	mul	a1,a1,s5
  for(p = proc; p < &proc[NPROC]; p++) {
    800021d0:	16840413          	add	s0,s0,360
    map_page(kpgtbl, va, (uint64)pa, PTE_R | PTE_W);
    800021d4:	4699                	li	a3,6
    800021d6:	854a                	mv	a0,s2
    uint64 va = KSTACK((int) (p - proc));
    800021d8:	2585                	addw	a1,a1,1
    800021da:	00d5959b          	sllw	a1,a1,0xd
    map_page(kpgtbl, va, (uint64)pa, PTE_R | PTE_W);
    800021de:	40b485b3          	sub	a1,s1,a1
    800021e2:	bc5fe0ef          	jal	80000da6 <map_page>
  for(p = proc; p < &proc[NPROC]; p++) {
    800021e6:	01440c63          	beq	s0,s4,800021fe <proc_mapstacks+0x7a>
    char *pa = alloc_page();
    800021ea:	90dfe0ef          	jal	80000af6 <alloc_page>
    800021ee:	862a                	mv	a2,a0
    if(pa == 0)
    800021f0:	f979                	bnez	a0,800021c6 <proc_mapstacks+0x42>
    800021f2:	e42a                	sd	a0,8(sp)
      panic("kalloc");
    800021f4:	855a                	mv	a0,s6
    800021f6:	faafe0ef          	jal	800009a0 <panic>
    800021fa:	6622                	ld	a2,8(sp)
    800021fc:	b7e9                	j	800021c6 <proc_mapstacks+0x42>
}
    800021fe:	60a6                	ld	ra,72(sp)
    80002200:	6406                	ld	s0,64(sp)
    80002202:	74e2                	ld	s1,56(sp)
    80002204:	7942                	ld	s2,48(sp)
    80002206:	79a2                	ld	s3,40(sp)
    80002208:	7a02                	ld	s4,32(sp)
    8000220a:	6ae2                	ld	s5,24(sp)
    8000220c:	6b42                	ld	s6,16(sp)
    8000220e:	6161                	add	sp,sp,80
    80002210:	8082                	ret

0000000080002212 <procinit>:
void procinit(void) {
    80002212:	7139                	add	sp,sp,-64
  initlock(&pid_lock, "nextpid");
    80002214:	00004597          	auipc	a1,0x4
    80002218:	e7c58593          	add	a1,a1,-388 # 80006090 <syscalls+0xe0>
    8000221c:	00004517          	auipc	a0,0x4
    80002220:	64450513          	add	a0,a0,1604 # 80006860 <pid_lock>
void procinit(void) {
    80002224:	fc06                	sd	ra,56(sp)
    80002226:	f822                	sd	s0,48(sp)
    80002228:	f426                	sd	s1,40(sp)
    8000222a:	f04a                	sd	s2,32(sp)
    8000222c:	ec4e                	sd	s3,24(sp)
    8000222e:	e852                	sd	s4,16(sp)
    80002230:	e456                	sd	s5,8(sp)
    p->kstack = KSTACK((int) (p - proc));
    80002232:	020004b7          	lui	s1,0x2000
  initlock(&pid_lock, "nextpid");
    80002236:	dcfff0ef          	jal	80002004 <initlock>
  initlock(&wait_lock, "wait_lock");
    8000223a:	00004597          	auipc	a1,0x4
    8000223e:	e5e58593          	add	a1,a1,-418 # 80006098 <syscalls+0xe8>
    80002242:	00004517          	auipc	a0,0x4
    80002246:	63650513          	add	a0,a0,1590 # 80006878 <wait_lock>
  for(p = proc; p < &proc[NPROC]; p++) {
    8000224a:	00004917          	auipc	s2,0x4
    8000224e:	64690913          	add	s2,s2,1606 # 80006890 <proc>
    p->kstack = KSTACK((int) (p - proc));
    80002252:	14fd                	add	s1,s1,-1 # 1ffffff <_entry-0x7e000001>
  initlock(&wait_lock, "wait_lock");
    80002254:	db1ff0ef          	jal	80002004 <initlock>
  for(p = proc; p < &proc[NPROC]; p++) {
    80002258:	844a                	mv	s0,s2
    8000225a:	00003a97          	auipc	s5,0x3
    8000225e:	3b6aba83          	ld	s5,950(s5) # 80005610 <kalloc+0x52>
    80002262:	0000aa17          	auipc	s4,0xa
    80002266:	02ea0a13          	add	s4,s4,46 # 8000c290 <bcache>
    initlock(&p->lock, "proc");
    8000226a:	00004997          	auipc	s3,0x4
    8000226e:	e3e98993          	add	s3,s3,-450 # 800060a8 <syscalls+0xf8>
    p->kstack = KSTACK((int) (p - proc));
    80002272:	04b6                	sll	s1,s1,0xd
    initlock(&p->lock, "proc");
    80002274:	8522                	mv	a0,s0
    80002276:	85ce                	mv	a1,s3
    80002278:	d8dff0ef          	jal	80002004 <initlock>
    p->kstack = KSTACK((int) (p - proc));
    8000227c:	412407b3          	sub	a5,s0,s2
    80002280:	878d                	sra	a5,a5,0x3
    80002282:	035787b3          	mul	a5,a5,s5
    p->state = UNUSED;
    80002286:	00042c23          	sw	zero,24(s0)
  for(p = proc; p < &proc[NPROC]; p++) {
    8000228a:	16840413          	add	s0,s0,360
    p->kstack = KSTACK((int) (p - proc));
    8000228e:	2785                	addw	a5,a5,1
    80002290:	00d7979b          	sllw	a5,a5,0xd
    80002294:	40f487b3          	sub	a5,s1,a5
    80002298:	f4f43823          	sd	a5,-176(s0)
  for(p = proc; p < &proc[NPROC]; p++) {
    8000229c:	fd441ce3          	bne	s0,s4,80002274 <procinit+0x62>
}
    800022a0:	7442                	ld	s0,48(sp)
    800022a2:	70e2                	ld	ra,56(sp)
    800022a4:	74a2                	ld	s1,40(sp)
    800022a6:	7902                	ld	s2,32(sp)
    800022a8:	69e2                	ld	s3,24(sp)
    800022aa:	6a42                	ld	s4,16(sp)
    800022ac:	6aa2                	ld	s5,8(sp)
  printf("procinit: initialized process table\n");
    800022ae:	00004517          	auipc	a0,0x4
    800022b2:	e0250513          	add	a0,a0,-510 # 800060b0 <syscalls+0x100>
}
    800022b6:	6121                	add	sp,sp,64
  printf("procinit: initialized process table\n");
    800022b8:	8cefe06f          	j	80000386 <printf>

00000000800022bc <freeproc>:
void freeproc(struct proc *p) {
    800022bc:	1101                	add	sp,sp,-32
    800022be:	e822                	sd	s0,16(sp)
    800022c0:	842a                	mv	s0,a0
  if(p->trapframe)
    800022c2:	6128                	ld	a0,64(a0)
void freeproc(struct proc *p) {
    800022c4:	ec06                	sd	ra,24(sp)
    800022c6:	e426                	sd	s1,8(sp)
    800022c8:	e04a                	sd	s2,0(sp)
  if(p->trapframe)
    800022ca:	c119                	beqz	a0,800022d0 <freeproc+0x14>
    free_page((void*)p->trapframe);
    800022cc:	83ffe0ef          	jal	80000b0a <free_page>
  if(p->pagetable)
    800022d0:	6464                	ld	s1,200(s0)
  p->trapframe = 0;
    800022d2:	04043023          	sd	zero,64(s0)
  if(p->pagetable)
    800022d6:	c88d                	beqz	s1,80002308 <freeproc+0x4c>
  uvmunmap(pagetable, TRAMPOLINE, 1, 0);  // 取消映射蹦床
    800022d8:	040005b7          	lui	a1,0x4000
    800022dc:	15fd                	add	a1,a1,-1 # 3ffffff <_entry-0x7c000001>
    800022de:	4681                	li	a3,0
    800022e0:	4605                	li	a2,1
    800022e2:	05b2                	sll	a1,a1,0xc
    800022e4:	8526                	mv	a0,s1
    proc_freepagetable(p->pagetable, p->sz);
    800022e6:	0c043903          	ld	s2,192(s0)
  uvmunmap(pagetable, TRAMPOLINE, 1, 0);  // 取消映射蹦床
    800022ea:	bf5fe0ef          	jal	80000ede <uvmunmap>
  uvmunmap(pagetable, TRAPFRAME, 1, 0);   // 取消映射陷阱帧
    800022ee:	020005b7          	lui	a1,0x2000
    800022f2:	15fd                	add	a1,a1,-1 # 1ffffff <_entry-0x7e000001>
    800022f4:	05b6                	sll	a1,a1,0xd
    800022f6:	8526                	mv	a0,s1
    800022f8:	4681                	li	a3,0
    800022fa:	4605                	li	a2,1
    800022fc:	be3fe0ef          	jal	80000ede <uvmunmap>
  uvmfree(pagetable, sz);
    80002300:	85ca                	mv	a1,s2
    80002302:	8526                	mv	a0,s1
    80002304:	d6bfe0ef          	jal	8000106e <uvmfree>
  p->name[0] = 0;
    80002308:	0c040823          	sb	zero,208(s0)
}
    8000230c:	60e2                	ld	ra,24(sp)
  p->pagetable = 0;
    8000230e:	0c043423          	sd	zero,200(s0)
  p->sz = 0;
    80002312:	0c043023          	sd	zero,192(s0)
  p->pid = 0;
    80002316:	02042823          	sw	zero,48(s0)
  p->parent = 0;
    8000231a:	02043c23          	sd	zero,56(s0)
  p->chan = 0;
    8000231e:	02043023          	sd	zero,32(s0)
  p->killed = 0;
    80002322:	02043423          	sd	zero,40(s0)
  p->state = UNUSED;
    80002326:	00042c23          	sw	zero,24(s0)
}
    8000232a:	6442                	ld	s0,16(sp)
    8000232c:	64a2                	ld	s1,8(sp)
    8000232e:	6902                	ld	s2,0(sp)
    80002330:	6105                	add	sp,sp,32
    80002332:	8082                	ret

0000000080002334 <proc_pagetable>:
pagetable_t proc_pagetable(struct proc *p) {
    80002334:	1101                	add	sp,sp,-32
    80002336:	e426                	sd	s1,8(sp)
    80002338:	ec06                	sd	ra,24(sp)
    8000233a:	e822                	sd	s0,16(sp)
    8000233c:	84aa                	mv	s1,a0
  pagetable = create_pagetable();
    8000233e:	a1dfe0ef          	jal	80000d5a <create_pagetable>
  if(pagetable == 0)
    80002342:	c139                	beqz	a0,80002388 <proc_pagetable+0x54>
if(map_page(pagetable, TRAPFRAME, (uint64)(p->trapframe), PTE_R | PTE_W) < 0){
    80002344:	020005b7          	lui	a1,0x2000
    80002348:	60b0                	ld	a2,64(s1)
    8000234a:	15fd                	add	a1,a1,-1 # 1ffffff <_entry-0x7e000001>
    8000234c:	4699                	li	a3,6
    8000234e:	05b6                	sll	a1,a1,0xd
    80002350:	842a                	mv	s0,a0
    80002352:	a55fe0ef          	jal	80000da6 <map_page>
    80002356:	02054663          	bltz	a0,80002382 <proc_pagetable+0x4e>
  if(map_page(pagetable, TRAMPOLINE, (uint64)trampoline, PTE_R | PTE_X) < 0){
    8000235a:	040005b7          	lui	a1,0x4000
    8000235e:	15fd                	add	a1,a1,-1 # 3ffffff <_entry-0x7c000001>
    80002360:	46a9                	li	a3,10
    80002362:	00016617          	auipc	a2,0x16
    80002366:	c9e60613          	add	a2,a2,-866 # 80018000 <trampoline>
    8000236a:	05b2                	sll	a1,a1,0xc
    8000236c:	8522                	mv	a0,s0
    8000236e:	a39fe0ef          	jal	80000da6 <map_page>
    80002372:	00054863          	bltz	a0,80002382 <proc_pagetable+0x4e>
}
    80002376:	60e2                	ld	ra,24(sp)
    80002378:	8522                	mv	a0,s0
    8000237a:	6442                	ld	s0,16(sp)
    8000237c:	64a2                	ld	s1,8(sp)
    8000237e:	6105                	add	sp,sp,32
    80002380:	8082                	ret
  destroy_pagetable(pagetable);
    80002382:	8522                	mv	a0,s0
    80002384:	9fdfe0ef          	jal	80000d80 <destroy_pagetable>
    return 0;
    80002388:	4401                	li	s0,0
}
    8000238a:	60e2                	ld	ra,24(sp)
    8000238c:	8522                	mv	a0,s0
    8000238e:	6442                	ld	s0,16(sp)
    80002390:	64a2                	ld	s1,8(sp)
    80002392:	6105                	add	sp,sp,32
    80002394:	8082                	ret

0000000080002396 <allocproc>:
struct proc* allocproc(void) {
    80002396:	1101                	add	sp,sp,-32
    80002398:	e822                	sd	s0,16(sp)
    8000239a:	e426                	sd	s1,8(sp)
    8000239c:	ec06                	sd	ra,24(sp)
    8000239e:	e04a                	sd	s2,0(sp)
  for(p = proc; p < &proc[NPROC]; p++) {
    800023a0:	00004417          	auipc	s0,0x4
    800023a4:	4f040413          	add	s0,s0,1264 # 80006890 <proc>
    800023a8:	0000a497          	auipc	s1,0xa
    800023ac:	ee848493          	add	s1,s1,-280 # 8000c290 <bcache>
    800023b0:	a039                	j	800023be <allocproc+0x28>
    800023b2:	16840413          	add	s0,s0,360
      release(&p->lock);
    800023b6:	d57ff0ef          	jal	8000210c <release>
  for(p = proc; p < &proc[NPROC]; p++) {
    800023ba:	0a940b63          	beq	s0,s1,80002470 <allocproc+0xda>
    acquire(&p->lock);
    800023be:	8522                	mv	a0,s0
    800023c0:	ca7ff0ef          	jal	80002066 <acquire>
    if(p->state == UNUSED) {
    800023c4:	4c1c                	lw	a5,24(s0)
      release(&p->lock);
    800023c6:	8522                	mv	a0,s0
    if(p->state == UNUSED) {
    800023c8:	f7ed                	bnez	a5,800023b2 <allocproc+0x1c>
  p->pid = nextpid++;
    800023ca:	00004797          	auipc	a5,0x4
    800023ce:	1e678793          	add	a5,a5,486 # 800065b0 <nextpid>
    800023d2:	4398                	lw	a4,0(a5)
  p->state = USED;
    800023d4:	4685                	li	a3,1
    800023d6:	cc14                	sw	a3,24(s0)
  p->pid = nextpid++;
    800023d8:	d818                	sw	a4,48(s0)
    800023da:	0017069b          	addw	a3,a4,1
    800023de:	c394                	sw	a3,0(a5)
  if((p->trapframe = (struct trapframe *)alloc_page()) == 0){
    800023e0:	f16fe0ef          	jal	80000af6 <alloc_page>
    800023e4:	e028                	sd	a0,64(s0)
    800023e6:	cd3d                	beqz	a0,80002464 <allocproc+0xce>
  p->pagetable = proc_pagetable(p);
    800023e8:	8522                	mv	a0,s0
    800023ea:	f4bff0ef          	jal	80002334 <proc_pagetable>
    800023ee:	e468                	sd	a0,200(s0)
  if(p->pagetable == 0){
    800023f0:	c935                	beqz	a0,80002464 <allocproc+0xce>
  memset(&p->context, 0, sizeof(p->context));
    800023f2:	07000613          	li	a2,112
    800023f6:	4581                	li	a1,0
    800023f8:	04840513          	add	a0,s0,72
    800023fc:	73f020ef          	jal	8000533a <memset>
  p->context.sp = p->kstack + PGSIZE;  // 设置内核栈顶
    80002400:	7c5c                	ld	a5,184(s0)
    80002402:	6705                	lui	a4,0x1
    80002404:	97ba                	add	a5,a5,a4
  p->context.ra = (uint64)forkret;  
    80002406:	00000717          	auipc	a4,0x0
    8000240a:	d3870713          	add	a4,a4,-712 # 8000213e <forkret>
    8000240e:	e438                	sd	a4,72(s0)
  p->context.sp = p->kstack + PGSIZE;  // 设置内核栈顶
    80002410:	e83c                	sd	a5,80(s0)
  char *code_page = alloc_page();
    80002412:	ee4fe0ef          	jal	80000af6 <alloc_page>
    80002416:	84aa                	mv	s1,a0
  if(code_page == 0){
    80002418:	c531                	beqz	a0,80002464 <allocproc+0xce>
  if(map_page(p->pagetable, 0, (uint64)code_page, PTE_R | PTE_X | PTE_U) < 0){
    8000241a:	6468                	ld	a0,200(s0)
    8000241c:	46e9                	li	a3,26
    8000241e:	8626                	mv	a2,s1
    80002420:	4581                	li	a1,0
    80002422:	985fe0ef          	jal	80000da6 <map_page>
    80002426:	04054d63          	bltz	a0,80002480 <allocproc+0xea>
  char *stack_page = alloc_page();
    8000242a:	eccfe0ef          	jal	80000af6 <alloc_page>
    8000242e:	892a                	mv	s2,a0
  if(stack_page == 0){
    80002430:	c131                	beqz	a0,80002474 <allocproc+0xde>
  memset(stack_page, 0, PGSIZE);
    80002432:	6605                	lui	a2,0x1
    80002434:	4581                	li	a1,0
    80002436:	705020ef          	jal	8000533a <memset>
  if(map_page(p->pagetable, PGSIZE, (uint64)stack_page, PTE_R | PTE_W | PTE_U) < 0){
    8000243a:	6468                	ld	a0,200(s0)
    8000243c:	46d9                	li	a3,22
    8000243e:	864a                	mv	a2,s2
    80002440:	6585                	lui	a1,0x1
    80002442:	965fe0ef          	jal	80000da6 <map_page>
    80002446:	04054863          	bltz	a0,80002496 <allocproc+0x100>
  p->trapframe->epc = 0;
    8000244a:	6038                	ld	a4,64(s0)
  p->trapframe->sp = PGSIZE * 2;
    8000244c:	6789                	lui	a5,0x2
  p->trapframe->epc = 0;
    8000244e:	00073c23          	sd	zero,24(a4)
  p->trapframe->sp = PGSIZE * 2;
    80002452:	fb1c                	sd	a5,48(a4)
  p->sz = PGSIZE * 2;
    80002454:	e07c                	sd	a5,192(s0)
}
    80002456:	60e2                	ld	ra,24(sp)
    80002458:	8522                	mv	a0,s0
    8000245a:	6442                	ld	s0,16(sp)
    8000245c:	64a2                	ld	s1,8(sp)
    8000245e:	6902                	ld	s2,0(sp)
    80002460:	6105                	add	sp,sp,32
    80002462:	8082                	ret
    freeproc(p);
    80002464:	8522                	mv	a0,s0
    80002466:	e57ff0ef          	jal	800022bc <freeproc>
    release(&p->lock);
    8000246a:	8522                	mv	a0,s0
    8000246c:	ca1ff0ef          	jal	8000210c <release>
  return 0;
    80002470:	4401                	li	s0,0
    80002472:	b7d5                	j	80002456 <allocproc+0xc0>
    uvmunmap(p->pagetable, 0, 1, 0);
    80002474:	6468                	ld	a0,200(s0)
    80002476:	4681                	li	a3,0
    80002478:	4605                	li	a2,1
    8000247a:	4581                	li	a1,0
    8000247c:	a63fe0ef          	jal	80000ede <uvmunmap>
    free_page(code_page);
    80002480:	8526                	mv	a0,s1
    free_page(stack_page);
    80002482:	e88fe0ef          	jal	80000b0a <free_page>
    freeproc(p);
    80002486:	8522                	mv	a0,s0
    80002488:	e35ff0ef          	jal	800022bc <freeproc>
    release(&p->lock);
    8000248c:	8522                	mv	a0,s0
    8000248e:	c7fff0ef          	jal	8000210c <release>
  return 0;
    80002492:	4401                	li	s0,0
    80002494:	b7c9                	j	80002456 <allocproc+0xc0>
    uvmunmap(p->pagetable, 0, 1, 0);
    80002496:	6468                	ld	a0,200(s0)
    80002498:	4681                	li	a3,0
    8000249a:	4605                	li	a2,1
    8000249c:	4581                	li	a1,0
    8000249e:	a41fe0ef          	jal	80000ede <uvmunmap>
    free_page(code_page);
    800024a2:	8526                	mv	a0,s1
    800024a4:	e66fe0ef          	jal	80000b0a <free_page>
    free_page(stack_page);
    800024a8:	854a                	mv	a0,s2
    800024aa:	bfe1                	j	80002482 <allocproc+0xec>

00000000800024ac <userinit>:
{
    800024ac:	1101                	add	sp,sp,-32
    800024ae:	ec06                	sd	ra,24(sp)
    800024b0:	e822                	sd	s0,16(sp)
    800024b2:	e426                	sd	s1,8(sp)
  p = allocproc();
    800024b4:	ee3ff0ef          	jal	80002396 <allocproc>
    800024b8:	842a                	mv	s0,a0
  if((pte = walk_lookup(p->pagetable, code_va)) == 0)
    800024ba:	6568                	ld	a0,200(a0)
    800024bc:	4581                	li	a1,0
  initproc = p;
    800024be:	00004797          	auipc	a5,0x4
    800024c2:	2087b123          	sd	s0,514(a5) # 800066c0 <initproc>
  if((pte = walk_lookup(p->pagetable, code_va)) == 0)
    800024c6:	87ffe0ef          	jal	80000d44 <walk_lookup>
    800024ca:	84aa                	mv	s1,a0
    800024cc:	c521                	beqz	a0,80002514 <userinit+0x68>
  if((*pte & PTE_V) == 0)
    800024ce:	609c                	ld	a5,0(s1)
    800024d0:	0017f713          	and	a4,a5,1
    800024d4:	cb05                	beqz	a4,80002504 <userinit+0x58>
  uint64 code_pa = PTE2PA(*pte);
    800024d6:	00a7d513          	srl	a0,a5,0xa
  memmove(code_page, test_program_bin, test_program_bin_len);
    800024da:	0da00613          	li	a2,218
    800024de:	00004597          	auipc	a1,0x4
    800024e2:	0e258593          	add	a1,a1,226 # 800065c0 <test_program_bin>
    800024e6:	0532                	sll	a0,a0,0xc
    800024e8:	6af020ef          	jal	80005396 <memmove>
  p->trapframe->epc = 0;
    800024ec:	603c                	ld	a5,64(s0)
  release(&p->lock);
    800024ee:	8522                	mv	a0,s0
}
    800024f0:	60e2                	ld	ra,24(sp)
  p->trapframe->epc = 0;
    800024f2:	0007bc23          	sd	zero,24(a5)
  p->state = RUNNABLE;
    800024f6:	478d                	li	a5,3
    800024f8:	cc1c                	sw	a5,24(s0)
}
    800024fa:	6442                	ld	s0,16(sp)
    800024fc:	64a2                	ld	s1,8(sp)
    800024fe:	6105                	add	sp,sp,32
  release(&p->lock);
    80002500:	c0dff06f          	j	8000210c <release>
    panic("load_test_program: code page not valid");
    80002504:	00004517          	auipc	a0,0x4
    80002508:	bfc50513          	add	a0,a0,-1028 # 80006100 <syscalls+0x150>
    8000250c:	c94fe0ef          	jal	800009a0 <panic>
  uint64 code_pa = PTE2PA(*pte);
    80002510:	609c                	ld	a5,0(s1)
    80002512:	b7d1                	j	800024d6 <userinit+0x2a>
    panic("load_test_program: code page not mapped");
    80002514:	00004517          	auipc	a0,0x4
    80002518:	bc450513          	add	a0,a0,-1084 # 800060d8 <syscalls+0x128>
    8000251c:	c84fe0ef          	jal	800009a0 <panic>
    80002520:	b77d                	j	800024ce <userinit+0x22>

0000000080002522 <proc_freepagetable>:
void proc_freepagetable(pagetable_t pagetable, uint64 sz) {
    80002522:	1101                	add	sp,sp,-32
  uvmunmap(pagetable, TRAMPOLINE, 1, 0);  // 取消映射蹦床
    80002524:	040007b7          	lui	a5,0x4000
void proc_freepagetable(pagetable_t pagetable, uint64 sz) {
    80002528:	e426                	sd	s1,8(sp)
    8000252a:	84ae                	mv	s1,a1
  uvmunmap(pagetable, TRAMPOLINE, 1, 0);  // 取消映射蹦床
    8000252c:	fff78593          	add	a1,a5,-1 # 3ffffff <_entry-0x7c000001>
    80002530:	4681                	li	a3,0
    80002532:	4605                	li	a2,1
    80002534:	05b2                	sll	a1,a1,0xc
void proc_freepagetable(pagetable_t pagetable, uint64 sz) {
    80002536:	ec06                	sd	ra,24(sp)
    80002538:	e822                	sd	s0,16(sp)
    8000253a:	842a                	mv	s0,a0
  uvmunmap(pagetable, TRAMPOLINE, 1, 0);  // 取消映射蹦床
    8000253c:	9a3fe0ef          	jal	80000ede <uvmunmap>
  uvmunmap(pagetable, TRAPFRAME, 1, 0);   // 取消映射陷阱帧
    80002540:	020005b7          	lui	a1,0x2000
    80002544:	15fd                	add	a1,a1,-1 # 1ffffff <_entry-0x7e000001>
    80002546:	8522                	mv	a0,s0
    80002548:	05b6                	sll	a1,a1,0xd
    8000254a:	4681                	li	a3,0
    8000254c:	4605                	li	a2,1
    8000254e:	991fe0ef          	jal	80000ede <uvmunmap>
  uvmfree(pagetable, sz);
    80002552:	8522                	mv	a0,s0
}
    80002554:	6442                	ld	s0,16(sp)
    80002556:	60e2                	ld	ra,24(sp)
  uvmfree(pagetable, sz);
    80002558:	85a6                	mv	a1,s1
}
    8000255a:	64a2                	ld	s1,8(sp)
    8000255c:	6105                	add	sp,sp,32
  uvmfree(pagetable, sz);
    8000255e:	b11fe06f          	j	8000106e <uvmfree>

0000000080002562 <myproc>:
}
    80002562:	00004517          	auipc	a0,0x4
    80002566:	27653503          	ld	a0,630(a0) # 800067d8 <cpus>
    8000256a:	8082                	ret

000000008000256c <uvmcopy>:
  pte_t *pte;
  uint64 pa, i;
  uint8 flags;
  
  // 遍历所有用户页面
  for(i = 0; i < sz; i += PGSIZE){
    8000256c:	ca71                	beqz	a2,80002640 <uvmcopy+0xd4>
int uvmcopy(pagetable_t old, pagetable_t new, uint64 sz) {
    8000256e:	715d                	add	sp,sp,-80
    80002570:	fc26                	sd	s1,56(sp)
    80002572:	f44e                	sd	s3,40(sp)
    80002574:	f052                	sd	s4,32(sp)
    80002576:	ec56                	sd	s5,24(sp)
    80002578:	e85a                	sd	s6,16(sp)
    8000257a:	e45e                	sd	s7,8(sp)
    8000257c:	e486                	sd	ra,72(sp)
    8000257e:	e0a2                	sd	s0,64(sp)
    80002580:	f84a                	sd	s2,48(sp)
    80002582:	8a32                	mv	s4,a2
    80002584:	8aaa                	mv	s5,a0
    80002586:	89ae                	mv	s3,a1
    80002588:	4481                	li	s1,0
    8000258a:	00004b97          	auipc	s7,0x4
    8000258e:	b9eb8b93          	add	s7,s7,-1122 # 80006128 <syscalls+0x178>
    80002592:	00004b17          	auipc	s6,0x4
    80002596:	bb6b0b13          	add	s6,s6,-1098 # 80006148 <syscalls+0x198>
    8000259a:	a80d                	j	800025cc <uvmcopy+0x60>
    if((pte = walk_lookup(old, i)) == 0)
      panic("uvmcopy: pte should exist");
    if((*pte & PTE_V) == 0)
      panic("uvmcopy: page not present");
    pa = PTE2PA(*pte);
    8000259c:	00a6d913          	srl	s2,a3,0xa
    800025a0:	0932                	sll	s2,s2,0xc
    flags = PTE_FLAGS(*pte);
    800025a2:	0ff6f413          	zext.b	s0,a3
    
    // 分配新页面
    void *mem = alloc_page();
    800025a6:	d50fe0ef          	jal	80000af6 <alloc_page>
    if(mem == 0)
      goto err;
    
    // 复制页面内容
    memmove(mem, (char*)pa, PGSIZE);
    800025aa:	85ca                	mv	a1,s2
    800025ac:	6605                	lui	a2,0x1
    void *mem = alloc_page();
    800025ae:	892a                	mv	s2,a0
    if(mem == 0)
    800025b0:	c521                	beqz	a0,800025f8 <uvmcopy+0x8c>
    memmove(mem, (char*)pa, PGSIZE);
    800025b2:	5e5020ef          	jal	80005396 <memmove>
    
    // 映射到新页表
    if(map_page(new, i, (uint64)mem, flags) != 0){
    800025b6:	86a2                	mv	a3,s0
    800025b8:	864a                	mv	a2,s2
    800025ba:	85a6                	mv	a1,s1
    800025bc:	854e                	mv	a0,s3
    800025be:	fe8fe0ef          	jal	80000da6 <map_page>
    800025c2:	e905                	bnez	a0,800025f2 <uvmcopy+0x86>
  for(i = 0; i < sz; i += PGSIZE){
    800025c4:	6785                	lui	a5,0x1
    800025c6:	94be                	add	s1,s1,a5
    800025c8:	0744fa63          	bgeu	s1,s4,8000263c <uvmcopy+0xd0>
    if((pte = walk_lookup(old, i)) == 0)
    800025cc:	85a6                	mv	a1,s1
    800025ce:	8556                	mv	a0,s5
    800025d0:	f74fe0ef          	jal	80000d44 <walk_lookup>
    800025d4:	842a                	mv	s0,a0
    800025d6:	c911                	beqz	a0,800025ea <uvmcopy+0x7e>
    if((*pte & PTE_V) == 0)
    800025d8:	6014                	ld	a3,0(s0)
    800025da:	0016f793          	and	a5,a3,1
    800025de:	ffdd                	bnez	a5,8000259c <uvmcopy+0x30>
      panic("uvmcopy: page not present");
    800025e0:	855a                	mv	a0,s6
    800025e2:	bbefe0ef          	jal	800009a0 <panic>
    pa = PTE2PA(*pte);
    800025e6:	6014                	ld	a3,0(s0)
    800025e8:	bf55                	j	8000259c <uvmcopy+0x30>
      panic("uvmcopy: pte should exist");
    800025ea:	855e                	mv	a0,s7
    800025ec:	bb4fe0ef          	jal	800009a0 <panic>
    800025f0:	b7e5                	j	800025d8 <uvmcopy+0x6c>
      free_page(mem);
    800025f2:	854a                	mv	a0,s2
    800025f4:	d16fe0ef          	jal	80000b0a <free_page>
  }
  return 0;

 err:
  // 释放已分配的页面
  for(uint64 j = 0; j < i; j += PGSIZE){
    800025f8:	4401                	li	s0,0
    800025fa:	6905                	lui	s2,0x1
    800025fc:	cc89                	beqz	s1,80002616 <uvmcopy+0xaa>
    pte_t *pte_new = walk_lookup(new, j);
    800025fe:	85a2                	mv	a1,s0
    80002600:	854e                	mv	a0,s3
    80002602:	f42fe0ef          	jal	80000d44 <walk_lookup>
  for(uint64 j = 0; j < i; j += PGSIZE){
    80002606:	944a                	add	s0,s0,s2
    if(pte_new && (*pte_new & PTE_V)){
    80002608:	c509                	beqz	a0,80002612 <uvmcopy+0xa6>
    8000260a:	6108                	ld	a0,0(a0)
    8000260c:	00157793          	and	a5,a0,1
    80002610:	ef99                	bnez	a5,8000262e <uvmcopy+0xc2>
  for(uint64 j = 0; j < i; j += PGSIZE){
    80002612:	fe9466e3          	bltu	s0,s1,800025fe <uvmcopy+0x92>
      uint64 pa = PTE2PA(*pte_new);
      free_page((void*)pa);
    }
  }
  return -1;
    80002616:	557d                	li	a0,-1
}
    80002618:	60a6                	ld	ra,72(sp)
    8000261a:	6406                	ld	s0,64(sp)
    8000261c:	74e2                	ld	s1,56(sp)
    8000261e:	7942                	ld	s2,48(sp)
    80002620:	79a2                	ld	s3,40(sp)
    80002622:	7a02                	ld	s4,32(sp)
    80002624:	6ae2                	ld	s5,24(sp)
    80002626:	6b42                	ld	s6,16(sp)
    80002628:	6ba2                	ld	s7,8(sp)
    8000262a:	6161                	add	sp,sp,80
    8000262c:	8082                	ret
      uint64 pa = PTE2PA(*pte_new);
    8000262e:	8129                	srl	a0,a0,0xa
      free_page((void*)pa);
    80002630:	0532                	sll	a0,a0,0xc
    80002632:	cd8fe0ef          	jal	80000b0a <free_page>
  for(uint64 j = 0; j < i; j += PGSIZE){
    80002636:	fc9464e3          	bltu	s0,s1,800025fe <uvmcopy+0x92>
    8000263a:	bff1                	j	80002616 <uvmcopy+0xaa>
  return 0;
    8000263c:	4501                	li	a0,0
    8000263e:	bfe9                	j	80002618 <uvmcopy+0xac>
    80002640:	4501                	li	a0,0
}
    80002642:	8082                	ret

0000000080002644 <wakeup>:
    }
  }
}

// 唤醒所有在chan上等待的进程
void wakeup(void *chan) {
    80002644:	7139                	add	sp,sp,-64
    80002646:	f822                	sd	s0,48(sp)
    80002648:	f426                	sd	s1,40(sp)
    8000264a:	f04a                	sd	s2,32(sp)
    8000264c:	ec4e                	sd	s3,24(sp)
    8000264e:	e852                	sd	s4,16(sp)
    80002650:	e456                	sd	s5,8(sp)
    80002652:	fc06                	sd	ra,56(sp)
    80002654:	8a2a                	mv	s4,a0
  struct proc *p;
  
  for(p = proc; p < &proc[NPROC]; p++){
    80002656:	00004417          	auipc	s0,0x4
    8000265a:	23a40413          	add	s0,s0,570 # 80006890 <proc>
    8000265e:	00004917          	auipc	s2,0x4
    80002662:	17a90913          	add	s2,s2,378 # 800067d8 <cpus>
    80002666:	0000a497          	auipc	s1,0xa
    8000266a:	c2a48493          	add	s1,s1,-982 # 8000c290 <bcache>
    if(p != myproc()){
      acquire(&p->lock);
      if(p->state == SLEEPING && p->chan == chan) {
    8000266e:	4989                	li	s3,2
        p->state = RUNNABLE;
    80002670:	4a8d                	li	s5,3
    80002672:	a039                	j	80002680 <wakeup+0x3c>
      }
      release(&p->lock);
    80002674:	a99ff0ef          	jal	8000210c <release>
  for(p = proc; p < &proc[NPROC]; p++){
    80002678:	16840413          	add	s0,s0,360
    8000267c:	02940363          	beq	s0,s1,800026a2 <wakeup+0x5e>
    if(p != myproc()){
    80002680:	00093783          	ld	a5,0(s2)
      acquire(&p->lock);
    80002684:	8522                	mv	a0,s0
    if(p != myproc()){
    80002686:	fe8789e3          	beq	a5,s0,80002678 <wakeup+0x34>
      acquire(&p->lock);
    8000268a:	9ddff0ef          	jal	80002066 <acquire>
      if(p->state == SLEEPING && p->chan == chan) {
    8000268e:	4c1c                	lw	a5,24(s0)
      release(&p->lock);
    80002690:	8522                	mv	a0,s0
      if(p->state == SLEEPING && p->chan == chan) {
    80002692:	ff3791e3          	bne	a5,s3,80002674 <wakeup+0x30>
    80002696:	701c                	ld	a5,32(s0)
    80002698:	fd479ee3          	bne	a5,s4,80002674 <wakeup+0x30>
        p->state = RUNNABLE;
    8000269c:	01542c23          	sw	s5,24(s0)
    800026a0:	bfd1                	j	80002674 <wakeup+0x30>
    }
  }
}
    800026a2:	70e2                	ld	ra,56(sp)
    800026a4:	7442                	ld	s0,48(sp)
    800026a6:	74a2                	ld	s1,40(sp)
    800026a8:	7902                	ld	s2,32(sp)
    800026aa:	69e2                	ld	s3,24(sp)
    800026ac:	6a42                	ld	s4,16(sp)
    800026ae:	6aa2                	ld	s5,8(sp)
    800026b0:	6121                	add	sp,sp,64
    800026b2:	8082                	ret

00000000800026b4 <reparent>:
void reparent(struct proc *p) {
    800026b4:	7179                	add	sp,sp,-48
    800026b6:	f022                	sd	s0,32(sp)
    800026b8:	ec26                	sd	s1,24(sp)
    800026ba:	e84a                	sd	s2,16(sp)
    800026bc:	e44e                	sd	s3,8(sp)
    800026be:	f406                	sd	ra,40(sp)
    800026c0:	84aa                	mv	s1,a0
  for(pp = proc; pp < &proc[NPROC]; pp++){
    800026c2:	00004417          	auipc	s0,0x4
    800026c6:	1ce40413          	add	s0,s0,462 # 80006890 <proc>
    800026ca:	0000a917          	auipc	s2,0xa
    800026ce:	bc690913          	add	s2,s2,-1082 # 8000c290 <bcache>
      pp->parent = initproc;
    800026d2:	00004997          	auipc	s3,0x4
    800026d6:	fee98993          	add	s3,s3,-18 # 800066c0 <initproc>
    800026da:	a029                	j	800026e4 <reparent+0x30>
  for(pp = proc; pp < &proc[NPROC]; pp++){
    800026dc:	16840413          	add	s0,s0,360
    800026e0:	01240f63          	beq	s0,s2,800026fe <reparent+0x4a>
    if(pp->parent == p){
    800026e4:	7c1c                	ld	a5,56(s0)
    800026e6:	fe979be3          	bne	a5,s1,800026dc <reparent+0x28>
      pp->parent = initproc;
    800026ea:	0009b503          	ld	a0,0(s3)
  for(pp = proc; pp < &proc[NPROC]; pp++){
    800026ee:	16840413          	add	s0,s0,360
      pp->parent = initproc;
    800026f2:	eca43823          	sd	a0,-304(s0)
      wakeup(initproc);
    800026f6:	f4fff0ef          	jal	80002644 <wakeup>
  for(pp = proc; pp < &proc[NPROC]; pp++){
    800026fa:	ff2415e3          	bne	s0,s2,800026e4 <reparent+0x30>
}
    800026fe:	70a2                	ld	ra,40(sp)
    80002700:	7402                	ld	s0,32(sp)
    80002702:	64e2                	ld	s1,24(sp)
    80002704:	6942                	ld	s2,16(sp)
    80002706:	69a2                	ld	s3,8(sp)
    80002708:	6145                	add	sp,sp,48
    8000270a:	8082                	ret

000000008000270c <sched>:
  // 释放p->lock
  release(&p->lock);
}

// 切换到调度器
void sched(void) {
    8000270c:	1101                	add	sp,sp,-32
    8000270e:	e822                	sd	s0,16(sp)
  return cpus[0].proc;
    80002710:	00004417          	auipc	s0,0x4
    80002714:	0c840413          	add	s0,s0,200 # 800067d8 <cpus>
void sched(void) {
    80002718:	e426                	sd	s1,8(sp)
  return cpus[0].proc;
    8000271a:	6004                	ld	s1,0(s0)
void sched(void) {
    8000271c:	ec06                	sd	ra,24(sp)
    8000271e:	e04a                	sd	s2,0(sp)
  int intena;
  struct proc *p = myproc();

  if(!holding(&p->lock))
    80002720:	8526                	mv	a0,s1
    80002722:	8fdff0ef          	jal	8000201e <holding>
    80002726:	c91d                	beqz	a0,8000275c <sched+0x50>
    panic("sched p->lock");
  if(p->state == RUNNING)
    80002728:	4c98                	lw	a4,24(s1)
    8000272a:	4791                	li	a5,4
    8000272c:	04f70263          	beq	a4,a5,80002770 <sched+0x64>
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80002730:	100027f3          	csrr	a5,sstatus
  return (x & SSTATUS_SIE) != 0;
    80002734:	8b89                	and	a5,a5,2
    panic("sched RUNNING");
  if(intr_get())
    80002736:	e7b9                	bnez	a5,80002784 <sched+0x78>
    panic("sched interruptible");

  intena = cpus[0].intena;
    80002738:	07c42903          	lw	s2,124(s0)
  swtch(&p->context, &cpus[0].context);
    8000273c:	04848513          	add	a0,s1,72
    80002740:	00004597          	auipc	a1,0x4
    80002744:	0a058593          	add	a1,a1,160 # 800067e0 <cpus+0x8>
    80002748:	794000ef          	jal	80002edc <swtch>
  cpus[0].intena = intena;
}
    8000274c:	60e2                	ld	ra,24(sp)
  cpus[0].intena = intena;
    8000274e:	07242e23          	sw	s2,124(s0)
}
    80002752:	6442                	ld	s0,16(sp)
    80002754:	64a2                	ld	s1,8(sp)
    80002756:	6902                	ld	s2,0(sp)
    80002758:	6105                	add	sp,sp,32
    8000275a:	8082                	ret
    panic("sched p->lock");
    8000275c:	00004517          	auipc	a0,0x4
    80002760:	a0c50513          	add	a0,a0,-1524 # 80006168 <syscalls+0x1b8>
    80002764:	a3cfe0ef          	jal	800009a0 <panic>
  if(p->state == RUNNING)
    80002768:	4c98                	lw	a4,24(s1)
    8000276a:	4791                	li	a5,4
    8000276c:	fcf712e3          	bne	a4,a5,80002730 <sched+0x24>
    panic("sched RUNNING");
    80002770:	00004517          	auipc	a0,0x4
    80002774:	a0850513          	add	a0,a0,-1528 # 80006178 <syscalls+0x1c8>
    80002778:	a28fe0ef          	jal	800009a0 <panic>
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    8000277c:	100027f3          	csrr	a5,sstatus
  return (x & SSTATUS_SIE) != 0;
    80002780:	8b89                	and	a5,a5,2
  if(intr_get())
    80002782:	dbdd                	beqz	a5,80002738 <sched+0x2c>
    panic("sched interruptible");
    80002784:	00004517          	auipc	a0,0x4
    80002788:	a0450513          	add	a0,a0,-1532 # 80006188 <syscalls+0x1d8>
    8000278c:	a14fe0ef          	jal	800009a0 <panic>
    80002790:	b765                	j	80002738 <sched+0x2c>

0000000080002792 <sleep>:
void sleep(void *chan, spinlock *lk) {
    80002792:	1101                	add	sp,sp,-32
    80002794:	e822                	sd	s0,16(sp)
  return cpus[0].proc;
    80002796:	00004417          	auipc	s0,0x4
    8000279a:	04243403          	ld	s0,66(s0) # 800067d8 <cpus>
void sleep(void *chan, spinlock *lk) {
    8000279e:	e04a                	sd	s2,0(sp)
    800027a0:	892a                	mv	s2,a0
  acquire(&p->lock);
    800027a2:	8522                	mv	a0,s0
void sleep(void *chan, spinlock *lk) {
    800027a4:	ec06                	sd	ra,24(sp)
    800027a6:	e426                	sd	s1,8(sp)
    800027a8:	84ae                	mv	s1,a1
  acquire(&p->lock);
    800027aa:	8bdff0ef          	jal	80002066 <acquire>
  release(lk);
    800027ae:	8526                	mv	a0,s1
    800027b0:	95dff0ef          	jal	8000210c <release>
  p->state = SLEEPING;
    800027b4:	4789                	li	a5,2
  p->chan = chan;
    800027b6:	03243023          	sd	s2,32(s0)
  p->state = SLEEPING;
    800027ba:	cc1c                	sw	a5,24(s0)
  sched();
    800027bc:	f51ff0ef          	jal	8000270c <sched>
  acquire(lk);
    800027c0:	8526                	mv	a0,s1
    800027c2:	8a5ff0ef          	jal	80002066 <acquire>
  release(&p->lock);
    800027c6:	8522                	mv	a0,s0
  p->chan = 0;
    800027c8:	02043023          	sd	zero,32(s0)
}
    800027cc:	6442                	ld	s0,16(sp)
    800027ce:	60e2                	ld	ra,24(sp)
    800027d0:	64a2                	ld	s1,8(sp)
    800027d2:	6902                	ld	s2,0(sp)
    800027d4:	6105                	add	sp,sp,32
  release(&p->lock);
    800027d6:	937ff06f          	j	8000210c <release>

00000000800027da <yield>:

// 让出CPU：将当前进程状态改为RUNNABLE并切换到调度器
void yield(void) {
    800027da:	1141                	add	sp,sp,-16
    800027dc:	e022                	sd	s0,0(sp)
  return cpus[0].proc;
    800027de:	00004417          	auipc	s0,0x4
    800027e2:	ffa43403          	ld	s0,-6(s0) # 800067d8 <cpus>
  struct proc *p = myproc();
  
  acquire(&p->lock);
    800027e6:	8522                	mv	a0,s0
void yield(void) {
    800027e8:	e406                	sd	ra,8(sp)
  acquire(&p->lock);
    800027ea:	87dff0ef          	jal	80002066 <acquire>
  p->state = RUNNABLE;
    800027ee:	478d                	li	a5,3
    800027f0:	cc1c                	sw	a5,24(s0)
  sched();
    800027f2:	f1bff0ef          	jal	8000270c <sched>
  release(&p->lock);
    800027f6:	8522                	mv	a0,s0
}
    800027f8:	6402                	ld	s0,0(sp)
    800027fa:	60a2                	ld	ra,8(sp)
    800027fc:	0141                	add	sp,sp,16
  release(&p->lock);
    800027fe:	90fff06f          	j	8000210c <release>

0000000080002802 <scheduler>:

// 调度器：永不返回的循环
// 每个CPU调用这个函数来调度进程
// 实现轮转调度，确保公平性
void scheduler(void) {
    80002802:	7159                	add	sp,sp,-112
  struct proc *p;
  struct cpu *c = &cpus[0];
 printf("scheduler: starting\n");
    80002804:	00004517          	auipc	a0,0x4
    80002808:	99c50513          	add	a0,a0,-1636 # 800061a0 <syscalls+0x1f0>
void scheduler(void) {
    8000280c:	eca6                	sd	s1,88(sp)
    8000280e:	e8ca                	sd	s2,80(sp)
    80002810:	e4ce                	sd	s3,72(sp)
    80002812:	e0d2                	sd	s4,64(sp)
    80002814:	fc56                	sd	s5,56(sp)
    80002816:	f85a                	sd	s6,48(sp)
    80002818:	f45e                	sd	s7,40(sp)
    8000281a:	ec66                	sd	s9,24(sp)
    8000281c:	f486                	sd	ra,104(sp)
    8000281e:	f0a2                	sd	s0,96(sp)
    80002820:	f062                	sd	s8,32(sp)
    80002822:	e86a                	sd	s10,16(sp)
    80002824:	e46e                	sd	s11,8(sp)
    80002826:	00004497          	auipc	s1,0x4
    8000282a:	06a48493          	add	s1,s1,106 # 80006890 <proc>
 printf("scheduler: starting\n");
    8000282e:	b59fd0ef          	jal	80000386 <printf>
  c->proc = 0;
  c->last_proc_idx = 0;  // 初始化从0开始
    80002832:	4c81                	li	s9,0
  c->proc = 0;
    80002834:	00004797          	auipc	a5,0x4
    80002838:	fa07b223          	sd	zero,-92(a5) # 800067d8 <cpus>
  c->last_proc_idx = 0;  // 初始化从0开始
    8000283c:	00004797          	auipc	a5,0x4
    80002840:	0007ae23          	sw	zero,28(a5) # 80006858 <cpus+0x80>
    80002844:	00004a17          	auipc	s4,0x4
    80002848:	f94a0a13          	add	s4,s4,-108 # 800067d8 <cpus>
    8000284c:	16800993          	li	s3,360
    for(int i = 0; i < NPROC; i++) {
      int idx = (start_idx + i) % NPROC;
      p = &proc[idx];
      
      acquire(&p->lock);
      if(p->state == RUNNABLE) {
    80002850:	490d                	li	s2,3
        //printf("scheduler: running process %d\n", p->pid);
        // 切换到选中的进程
        p->state = RUNNING;
    80002852:	4b11                	li	s6,4
        c->proc = p;
        c->last_proc_idx = (idx + 1) % NPROC;  // 更新下次起始位置
        swtch(&c->context, &p->context);
    80002854:	00004a97          	auipc	s5,0x4
    80002858:	f8ca8a93          	add	s5,s5,-116 # 800067e0 <cpus+0x8>
        break;
    }
    
    if(found == 0) {
      // 没有可运行的进程，等待中断
      printf("scheduler: no runnable process found, waiting...\n");
    8000285c:	00004b97          	auipc	s7,0x4
    80002860:	95cb8b93          	add	s7,s7,-1700 # 800061b8 <syscalls+0x208>
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80002864:	100027f3          	csrr	a5,sstatus
  w_sstatus(r_sstatus() | SSTATUS_SIE);
    80002868:	0027e793          	or	a5,a5,2
  asm volatile("csrw sstatus, %0" : : "r" (x));
    8000286c:	10079073          	csrw	sstatus,a5
  asm volatile("csrr %0, sstatus" : "=r" (x) );
    80002870:	100027f3          	csrr	a5,sstatus
  w_sstatus(r_sstatus() & ~SSTATUS_SIE);
    80002874:	9bf5                	and	a5,a5,-3
  asm volatile("csrw sstatus, %0" : : "r" (x));
    80002876:	10079073          	csrw	sstatus,a5
    for(int i = 0; i < NPROC; i++) {
    8000287a:	000c8c1b          	sext.w	s8,s9
    8000287e:	040c8c9b          	addw	s9,s9,64
    80002882:	a029                	j	8000288c <scheduler+0x8a>
      release(&p->lock);
    80002884:	889ff0ef          	jal	8000210c <release>
    for(int i = 0; i < NPROC; i++) {
    80002888:	078c8963          	beq	s9,s8,800028fa <scheduler+0xf8>
      int idx = (start_idx + i) % NPROC;
    8000288c:	41fc579b          	sraw	a5,s8,0x1f
    80002890:	01a7d79b          	srlw	a5,a5,0x1a
    80002894:	0187843b          	addw	s0,a5,s8
    80002898:	03f47413          	and	s0,s0,63
    8000289c:	40f40dbb          	subw	s11,s0,a5
    800028a0:	846e                	mv	s0,s11
      p = &proc[idx];
    800028a2:	033d8db3          	mul	s11,s11,s3
    for(int i = 0; i < NPROC; i++) {
    800028a6:	2c05                	addw	s8,s8,1
      p = &proc[idx];
    800028a8:	01b48d33          	add	s10,s1,s11
      acquire(&p->lock);
    800028ac:	856a                	mv	a0,s10
    800028ae:	fb8ff0ef          	jal	80002066 <acquire>
      if(p->state == RUNNABLE) {
    800028b2:	018d2783          	lw	a5,24(s10)
      release(&p->lock);
    800028b6:	856a                	mv	a0,s10
      if(p->state == RUNNABLE) {
    800028b8:	fd2796e3          	bne	a5,s2,80002884 <scheduler+0x82>
        c->last_proc_idx = (idx + 1) % NPROC;  // 更新下次起始位置
    800028bc:	2405                	addw	s0,s0,1
    800028be:	41f4579b          	sraw	a5,s0,0x1f
    800028c2:	01a7d79b          	srlw	a5,a5,0x1a
    800028c6:	9c3d                	addw	s0,s0,a5
    800028c8:	03f47413          	and	s0,s0,63
        swtch(&c->context, &p->context);
    800028cc:	048d8593          	add	a1,s11,72
        c->last_proc_idx = (idx + 1) % NPROC;  // 更新下次起始位置
    800028d0:	9c1d                	subw	s0,s0,a5
        swtch(&c->context, &p->context);
    800028d2:	95a6                	add	a1,a1,s1
    800028d4:	8556                	mv	a0,s5
        p->state = RUNNING;
    800028d6:	016d2c23          	sw	s6,24(s10)
        c->proc = p;
    800028da:	01aa3023          	sd	s10,0(s4)
        c->last_proc_idx = (idx + 1) % NPROC;  // 更新下次起始位置
    800028de:	088a2023          	sw	s0,128(s4)
        swtch(&c->context, &p->context);
    800028e2:	5fa000ef          	jal	80002edc <swtch>
      release(&p->lock);
    800028e6:	856a                	mv	a0,s10
        c->proc = 0;
    800028e8:	00004797          	auipc	a5,0x4
    800028ec:	ee07b823          	sd	zero,-272(a5) # 800067d8 <cpus>
      release(&p->lock);
    800028f0:	81dff0ef          	jal	8000210c <release>
    int start_idx = c->last_proc_idx;
    800028f4:	080a2c83          	lw	s9,128(s4)
    800028f8:	b7b5                	j	80002864 <scheduler+0x62>
      printf("scheduler: no runnable process found, waiting...\n");
    800028fa:	855e                	mv	a0,s7
    800028fc:	a8bfd0ef          	jal	80000386 <printf>
      asm volatile("wfi");
    80002900:	10500073          	wfi
    int start_idx = c->last_proc_idx;
    80002904:	080a2c83          	lw	s9,128(s4)
    80002908:	bfb1                	j	80002864 <scheduler+0x62>

000000008000290a <fork>:
    }
  }
}

// 创建新进程（fork）
int fork(void) {
    8000290a:	1101                	add	sp,sp,-32
    8000290c:	e426                	sd	s1,8(sp)
    8000290e:	ec06                	sd	ra,24(sp)
    80002910:	e822                	sd	s0,16(sp)
    80002912:	e04a                	sd	s2,0(sp)
  return cpus[0].proc;
    80002914:	00004497          	auipc	s1,0x4
    80002918:	ec44b483          	ld	s1,-316(s1) # 800067d8 <cpus>
  int i, pid;
  struct proc *np;
  struct proc *p = myproc();

  // 分配新进程
  if((np = allocproc()) == 0){
    8000291c:	a7bff0ef          	jal	80002396 <allocproc>
    80002920:	c555                	beqz	a0,800029cc <fork+0xc2>
    return -1;
  }

  // 复制用户内存（如果sz > 0）
  if(p->sz > 0){
    80002922:	60f0                	ld	a2,192(s1)
    80002924:	842a                	mv	s0,a0
    80002926:	e649                	bnez	a2,800029b0 <fork+0xa6>
    }
  }
  np->sz = p->sz;

  // 复制陷阱帧
  *(np->trapframe) = *(p->trapframe);
    80002928:	60bc                	ld	a5,64(s1)
    8000292a:	04043883          	ld	a7,64(s0)
  np->sz = p->sz;
    8000292e:	e070                	sd	a2,192(s0)
  *(np->trapframe) = *(p->trapframe);
    80002930:	12078813          	add	a6,a5,288
    80002934:	8746                	mv	a4,a7
    80002936:	6388                	ld	a0,0(a5)
    80002938:	678c                	ld	a1,8(a5)
    8000293a:	6b90                	ld	a2,16(a5)
    8000293c:	6f94                	ld	a3,24(a5)
    8000293e:	e308                	sd	a0,0(a4)
    80002940:	e70c                	sd	a1,8(a4)
    80002942:	eb10                	sd	a2,16(a4)
    80002944:	ef14                	sd	a3,24(a4)
    80002946:	02078793          	add	a5,a5,32
    8000294a:	02070713          	add	a4,a4,32
    8000294e:	ff0794e3          	bne	a5,a6,80002936 <fork+0x2c>

  // 子进程fork返回0
  np->trapframe->a0 = 0;
    80002952:	0608b823          	sd	zero,112(a7)

  // 复制文件描述符（暂不实现）
  for(i = 0; i < NOFILE; i++)
    80002956:	0e848793          	add	a5,s1,232
    8000295a:	0e840713          	add	a4,s0,232
    8000295e:	16848613          	add	a2,s1,360
    if(p->ofile[i])
    80002962:	6394                	ld	a3,0(a5)
  for(i = 0; i < NOFILE; i++)
    80002964:	07a1                	add	a5,a5,8
    if(p->ofile[i])
    80002966:	c291                	beqz	a3,8000296a <fork+0x60>
      np->ofile[i] = p->ofile[i];
    80002968:	e314                	sd	a3,0(a4)
  for(i = 0; i < NOFILE; i++)
    8000296a:	0721                	add	a4,a4,8
    8000296c:	fec79be3          	bne	a5,a2,80002962 <fork+0x58>
  np->cwd = p->cwd;
    80002970:	70fc                	ld	a5,224(s1)

  // 设置父进程
  pid = np->pid;
  
  acquire(&wait_lock);
    80002972:	00004517          	auipc	a0,0x4
    80002976:	f0650513          	add	a0,a0,-250 # 80006878 <wait_lock>
  pid = np->pid;
    8000297a:	03042903          	lw	s2,48(s0)
  np->cwd = p->cwd;
    8000297e:	f07c                	sd	a5,224(s0)
  acquire(&wait_lock);
    80002980:	ee6ff0ef          	jal	80002066 <acquire>
  np->parent = p;
  release(&wait_lock);
    80002984:	00004517          	auipc	a0,0x4
    80002988:	ef450513          	add	a0,a0,-268 # 80006878 <wait_lock>
  np->parent = p;
    8000298c:	fc04                	sd	s1,56(s0)
  release(&wait_lock);
    8000298e:	f7eff0ef          	jal	8000210c <release>

  acquire(&np->lock);
    80002992:	8522                	mv	a0,s0
    80002994:	ed2ff0ef          	jal	80002066 <acquire>
  np->state = RUNNABLE;
    80002998:	478d                	li	a5,3
    8000299a:	cc1c                	sw	a5,24(s0)
  release(&np->lock);
    8000299c:	8522                	mv	a0,s0
    8000299e:	f6eff0ef          	jal	8000210c <release>

  return pid;
}
    800029a2:	60e2                	ld	ra,24(sp)
    800029a4:	6442                	ld	s0,16(sp)
    800029a6:	64a2                	ld	s1,8(sp)
    800029a8:	854a                	mv	a0,s2
    800029aa:	6902                	ld	s2,0(sp)
    800029ac:	6105                	add	sp,sp,32
    800029ae:	8082                	ret
    if(uvmcopy(p->pagetable, np->pagetable, p->sz) < 0){
    800029b0:	656c                	ld	a1,200(a0)
    800029b2:	64e8                	ld	a0,200(s1)
    800029b4:	bb9ff0ef          	jal	8000256c <uvmcopy>
    800029b8:	00054463          	bltz	a0,800029c0 <fork+0xb6>
  np->sz = p->sz;
    800029bc:	60f0                	ld	a2,192(s1)
    800029be:	b7ad                	j	80002928 <fork+0x1e>
      freeproc(np);
    800029c0:	8522                	mv	a0,s0
    800029c2:	8fbff0ef          	jal	800022bc <freeproc>
      release(&np->lock);
    800029c6:	8522                	mv	a0,s0
    800029c8:	f44ff0ef          	jal	8000210c <release>
    return -1;
    800029cc:	597d                	li	s2,-1
    800029ce:	bfd1                	j	800029a2 <fork+0x98>

00000000800029d0 <exit>:

// 退出当前进程
void exit(int status) {
    800029d0:	7179                	add	sp,sp,-48
    800029d2:	ec26                	sd	s1,24(sp)
    800029d4:	e052                	sd	s4,0(sp)
    800029d6:	f406                	sd	ra,40(sp)
    800029d8:	f022                	sd	s0,32(sp)
    800029da:	e84a                	sd	s2,16(sp)
    800029dc:	e44e                	sd	s3,8(sp)
  return cpus[0].proc;
    800029de:	00004497          	auipc	s1,0x4
    800029e2:	dfa4b483          	ld	s1,-518(s1) # 800067d8 <cpus>
void exit(int status) {
    800029e6:	8a2a                	mv	s4,a0
  struct proc *p = myproc();
  if(p == 0)
    800029e8:	c4e9                	beqz	s1,80002ab2 <exit+0xe2>
    panic("exit");
  
  // 持有进程锁
  acquire(&p->lock);
    800029ea:	8526                	mv	a0,s1
    800029ec:	e7aff0ef          	jal	80002066 <acquire>
  printf("exit: %d\n", p->pid);
    800029f0:	588c                	lw	a1,48(s1)
    800029f2:	00004517          	auipc	a0,0x4
    800029f6:	80650513          	add	a0,a0,-2042 # 800061f8 <syscalls+0x248>
  // 如果有init进程且当前进程是init，则panic
  if(initproc && p == initproc)
    800029fa:	00004997          	auipc	s3,0x4
    800029fe:	cc698993          	add	s3,s3,-826 # 800066c0 <initproc>
  printf("exit: %d\n", p->pid);
    80002a02:	985fd0ef          	jal	80000386 <printf>
  if(initproc && p == initproc)
    80002a06:	0009b783          	ld	a5,0(s3)
    80002a0a:	c399                	beqz	a5,80002a10 <exit+0x40>
    80002a0c:	08978c63          	beq	a5,s1,80002aa4 <exit+0xd4>
    80002a10:	0e848793          	add	a5,s1,232
    80002a14:	16848693          	add	a3,s1,360
    panic("init exiting");

  // 关闭所有打开的文件（暂不实现文件系统，只清空指针）
  for(int fd = 0; fd < NOFILE; fd++){
    if(p->ofile[fd]){
    80002a18:	6398                	ld	a4,0(a5)
    80002a1a:	c319                	beqz	a4,80002a20 <exit+0x50>
      p->ofile[fd] = 0;
    80002a1c:	0007b023          	sd	zero,0(a5)
  for(int fd = 0; fd < NOFILE; fd++){
    80002a20:	07a1                	add	a5,a5,8
    80002a22:	fed79be3          	bne	a5,a3,80002a18 <exit+0x48>
    }
  }

  // 开始退出：获取wait_lock
  acquire(&wait_lock);
    80002a26:	00004517          	auipc	a0,0x4
    80002a2a:	e5250513          	add	a0,a0,-430 # 80006878 <wait_lock>
    80002a2e:	e38ff0ef          	jal	80002066 <acquire>

  // 如果有init进程，将子进程交给init
  if(initproc) {
    80002a32:	0009b783          	ld	a5,0(s3)
    80002a36:	cb9d                	beqz	a5,80002a6c <exit+0x9c>
  for(pp = proc; pp < &proc[NPROC]; pp++){
    80002a38:	00004417          	auipc	s0,0x4
    80002a3c:	e5840413          	add	s0,s0,-424 # 80006890 <proc>
    80002a40:	0000a917          	auipc	s2,0xa
    80002a44:	85090913          	add	s2,s2,-1968 # 8000c290 <bcache>
    80002a48:	a029                	j	80002a52 <exit+0x82>
    80002a4a:	16840413          	add	s0,s0,360
    80002a4e:	01240f63          	beq	s0,s2,80002a6c <exit+0x9c>
    if(pp->parent == p){
    80002a52:	7c1c                	ld	a5,56(s0)
    80002a54:	fef49be3          	bne	s1,a5,80002a4a <exit+0x7a>
      pp->parent = initproc;
    80002a58:	0009b503          	ld	a0,0(s3)
  for(pp = proc; pp < &proc[NPROC]; pp++){
    80002a5c:	16840413          	add	s0,s0,360
      pp->parent = initproc;
    80002a60:	eca43823          	sd	a0,-304(s0)
      wakeup(initproc);
    80002a64:	be1ff0ef          	jal	80002644 <wakeup>
  for(pp = proc; pp < &proc[NPROC]; pp++){
    80002a68:	ff2415e3          	bne	s0,s2,80002a52 <exit+0x82>
    reparent(p);
  }
  
  // 唤醒父进程（如果有的话）
  wakeup(p->parent);
    80002a6c:	7c88                	ld	a0,56(s1)
    80002a6e:	bd7ff0ef          	jal	80002644 <wakeup>

  // 设置退出状态和进程状态
  p->xstate = status;
  p->state = ZOMBIE;
    80002a72:	4795                	li	a5,5

  // 释放wait_lock，但保留p->lock（sched()需要持有它）
  release(&wait_lock);
    80002a74:	00004517          	auipc	a0,0x4
    80002a78:	e0450513          	add	a0,a0,-508 # 80006878 <wait_lock>
  p->xstate = status;
    80002a7c:	0344a623          	sw	s4,44(s1)
  p->state = ZOMBIE;
    80002a80:	cc9c                	sw	a5,24(s1)
  release(&wait_lock);
    80002a82:	e8aff0ef          	jal	8000210c <release>
  
  // 切换到调度器（永不返回），scheduler会释放p->lock
  sched();
    80002a86:	c87ff0ef          	jal	8000270c <sched>
  panic("zombie exit");
}
    80002a8a:	7402                	ld	s0,32(sp)
    80002a8c:	70a2                	ld	ra,40(sp)
    80002a8e:	64e2                	ld	s1,24(sp)
    80002a90:	6942                	ld	s2,16(sp)
    80002a92:	69a2                	ld	s3,8(sp)
    80002a94:	6a02                	ld	s4,0(sp)
  panic("zombie exit");
    80002a96:	00003517          	auipc	a0,0x3
    80002a9a:	78250513          	add	a0,a0,1922 # 80006218 <syscalls+0x268>
}
    80002a9e:	6145                	add	sp,sp,48
  panic("zombie exit");
    80002aa0:	f01fd06f          	j	800009a0 <panic>
    panic("init exiting");
    80002aa4:	00003517          	auipc	a0,0x3
    80002aa8:	76450513          	add	a0,a0,1892 # 80006208 <syscalls+0x258>
    80002aac:	ef5fd0ef          	jal	800009a0 <panic>
  for(int fd = 0; fd < NOFILE; fd++){
    80002ab0:	b785                	j	80002a10 <exit+0x40>
    panic("exit");
    80002ab2:	00003517          	auipc	a0,0x3
    80002ab6:	73e50513          	add	a0,a0,1854 # 800061f0 <syscalls+0x240>
    80002aba:	ee7fd0ef          	jal	800009a0 <panic>
  acquire(&p->lock);
    80002abe:	4501                	li	a0,0
    80002ac0:	da6ff0ef          	jal	80002066 <acquire>
  printf("exit: %d\n", p->pid);
    80002ac4:	03002583          	lw	a1,48(zero) # 30 <_entry-0x7fffffd0>
    80002ac8:	00003517          	auipc	a0,0x3
    80002acc:	73050513          	add	a0,a0,1840 # 800061f8 <syscalls+0x248>
    80002ad0:	00004997          	auipc	s3,0x4
    80002ad4:	bf098993          	add	s3,s3,-1040 # 800066c0 <initproc>
    80002ad8:	8affd0ef          	jal	80000386 <printf>
  if(initproc && p == initproc)
    80002adc:	bf15                	j	80002a10 <exit+0x40>

0000000080002ade <wait>:

// 等待子进程退出并回收
int wait(uint64 addr) {
    80002ade:	715d                	add	sp,sp,-80
    80002ae0:	f052                	sd	s4,32(sp)
    80002ae2:	e85a                	sd	s6,16(sp)
    80002ae4:	8a2a                	mv	s4,a0
  return cpus[0].proc;
    80002ae6:	00004b17          	auipc	s6,0x4
    80002aea:	cf2b0b13          	add	s6,s6,-782 # 800067d8 <cpus>
  struct proc *pp;
  int havekids, pid;
  struct proc *p = myproc();

  acquire(&wait_lock);
    80002aee:	00004517          	auipc	a0,0x4
    80002af2:	d8a50513          	add	a0,a0,-630 # 80006878 <wait_lock>
int wait(uint64 addr) {
    80002af6:	fc26                	sd	s1,56(sp)
    80002af8:	f84a                	sd	s2,48(sp)
    80002afa:	f44e                	sd	s3,40(sp)
    80002afc:	ec56                	sd	s5,24(sp)
    80002afe:	e45e                	sd	s7,8(sp)
  return cpus[0].proc;
    80002b00:	000b3483          	ld	s1,0(s6)
int wait(uint64 addr) {
    80002b04:	e486                	sd	ra,72(sp)
    80002b06:	e0a2                	sd	s0,64(sp)
    for(pp = proc; pp < &proc[NPROC]; pp++){
      if(pp->parent == p){
        // 确保子进程不在exit()或swtch()中
        acquire(&pp->lock);
        havekids = 1;
        if(pp->state == ZOMBIE){
    80002b08:	4995                	li	s3,5
  acquire(&wait_lock);
    80002b0a:	d5cff0ef          	jal	80002066 <acquire>
    for(pp = proc; pp < &proc[NPROC]; pp++){
    80002b0e:	00009917          	auipc	s2,0x9
    80002b12:	78290913          	add	s2,s2,1922 # 8000c290 <bcache>
  release(lk);
    80002b16:	00004a97          	auipc	s5,0x4
    80002b1a:	d62a8a93          	add	s5,s5,-670 # 80006878 <wait_lock>
  p->state = SLEEPING;
    80002b1e:	4b89                	li	s7,2
    havekids = 0;
    80002b20:	4701                	li	a4,0
    for(pp = proc; pp < &proc[NPROC]; pp++){
    80002b22:	00004417          	auipc	s0,0x4
    80002b26:	d6e40413          	add	s0,s0,-658 # 80006890 <proc>
    80002b2a:	a029                	j	80002b34 <wait+0x56>
    80002b2c:	16840413          	add	s0,s0,360
    80002b30:	03240363          	beq	s0,s2,80002b56 <wait+0x78>
      if(pp->parent == p){
    80002b34:	7c1c                	ld	a5,56(s0)
    80002b36:	fe979be3          	bne	a5,s1,80002b2c <wait+0x4e>
        acquire(&pp->lock);
    80002b3a:	8522                	mv	a0,s0
    80002b3c:	d2aff0ef          	jal	80002066 <acquire>
        if(pp->state == ZOMBIE){
    80002b40:	4c1c                	lw	a5,24(s0)
          freeproc(pp);
          release(&pp->lock);
          release(&wait_lock);
          return pid;
        }
        release(&pp->lock);
    80002b42:	8522                	mv	a0,s0
        if(pp->state == ZOMBIE){
    80002b44:	05378063          	beq	a5,s3,80002b84 <wait+0xa6>
        release(&pp->lock);
    80002b48:	dc4ff0ef          	jal	8000210c <release>
    for(pp = proc; pp < &proc[NPROC]; pp++){
    80002b4c:	16840413          	add	s0,s0,360
        havekids = 1;
    80002b50:	4705                	li	a4,1
    for(pp = proc; pp < &proc[NPROC]; pp++){
    80002b52:	ff2411e3          	bne	s0,s2,80002b34 <wait+0x56>
      }
    }

    // 如果没有子进程，返回-1
    if(!havekids){
    80002b56:	cb25                	beqz	a4,80002bc6 <wait+0xe8>
  return cpus[0].proc;
    80002b58:	000b3403          	ld	s0,0(s6)
  acquire(&p->lock);
    80002b5c:	8522                	mv	a0,s0
    80002b5e:	d08ff0ef          	jal	80002066 <acquire>
  release(lk);
    80002b62:	8556                	mv	a0,s5
    80002b64:	da8ff0ef          	jal	8000210c <release>
  p->chan = chan;
    80002b68:	f004                	sd	s1,32(s0)
  p->state = SLEEPING;
    80002b6a:	01742c23          	sw	s7,24(s0)
  sched();
    80002b6e:	b9fff0ef          	jal	8000270c <sched>
  acquire(lk);
    80002b72:	8556                	mv	a0,s5
    80002b74:	cf2ff0ef          	jal	80002066 <acquire>
  release(&p->lock);
    80002b78:	8522                	mv	a0,s0
  p->chan = 0;
    80002b7a:	02043023          	sd	zero,32(s0)
  release(&p->lock);
    80002b7e:	d8eff0ef          	jal	8000210c <release>
}
    80002b82:	bf79                	j	80002b20 <wait+0x42>
          pid = pp->pid;
    80002b84:	5804                	lw	s1,48(s0)
          if(addr != 0 && copyout(p->pagetable, addr, (char *)&pp->xstate,
    80002b86:	000a0863          	beqz	s4,80002b96 <wait+0xb8>
  // 注意：在没有实现完整页表walk的情况下，这只是一个基本实现
  uint64 n;
  
  while(len > 0){
    n = len < PGSIZE ? len : PGSIZE;
    memmove((void*)dstva, src, n);
    80002b8a:	4611                	li	a2,4
    80002b8c:	02c40593          	add	a1,s0,44
    80002b90:	8552                	mv	a0,s4
    80002b92:	005020ef          	jal	80005396 <memmove>
          freeproc(pp);
    80002b96:	8522                	mv	a0,s0
    80002b98:	f24ff0ef          	jal	800022bc <freeproc>
          release(&pp->lock);
    80002b9c:	8522                	mv	a0,s0
    80002b9e:	d6eff0ef          	jal	8000210c <release>
          release(&wait_lock);
    80002ba2:	00004517          	auipc	a0,0x4
    80002ba6:	cd650513          	add	a0,a0,-810 # 80006878 <wait_lock>
    80002baa:	d62ff0ef          	jal	8000210c <release>
}
    80002bae:	60a6                	ld	ra,72(sp)
    80002bb0:	6406                	ld	s0,64(sp)
    80002bb2:	7942                	ld	s2,48(sp)
    80002bb4:	79a2                	ld	s3,40(sp)
    80002bb6:	7a02                	ld	s4,32(sp)
    80002bb8:	6ae2                	ld	s5,24(sp)
    80002bba:	6b42                	ld	s6,16(sp)
    80002bbc:	6ba2                	ld	s7,8(sp)
    80002bbe:	8526                	mv	a0,s1
    80002bc0:	74e2                	ld	s1,56(sp)
    80002bc2:	6161                	add	sp,sp,80
    80002bc4:	8082                	ret
      release(&wait_lock);
    80002bc6:	00004517          	auipc	a0,0x4
    80002bca:	cb250513          	add	a0,a0,-846 # 80006878 <wait_lock>
    80002bce:	d3eff0ef          	jal	8000210c <release>
            return -1;
    80002bd2:	54fd                	li	s1,-1
    80002bd4:	bfe9                	j	80002bae <wait+0xd0>

0000000080002bd6 <copyout>:
  while(len > 0){
    80002bd6:	c2b9                	beqz	a3,80002c1c <copyout+0x46>
int copyout(pagetable_t pagetable, uint64 dstva, void *src, uint64 len) {
    80002bd8:	7179                	add	sp,sp,-48
    80002bda:	ec26                	sd	s1,24(sp)
    80002bdc:	e84a                	sd	s2,16(sp)
    80002bde:	e44e                	sd	s3,8(sp)
    80002be0:	e052                	sd	s4,0(sp)
    80002be2:	f406                	sd	ra,40(sp)
    80002be4:	f022                	sd	s0,32(sp)
    80002be6:	84b6                	mv	s1,a3
    80002be8:	892e                	mv	s2,a1
    80002bea:	89b2                	mv	s3,a2
    n = len < PGSIZE ? len : PGSIZE;
    80002bec:	6a05                	lui	s4,0x1
    memmove((void*)dstva, src, n);
    80002bee:	85ce                	mv	a1,s3
    80002bf0:	854a                	mv	a0,s2
    n = len < PGSIZE ? len : PGSIZE;
    80002bf2:	8426                	mv	s0,s1
    80002bf4:	009a7363          	bgeu	s4,s1,80002bfa <copyout+0x24>
    80002bf8:	6405                	lui	s0,0x1
    memmove((void*)dstva, src, n);
    80002bfa:	0004061b          	sext.w	a2,s0
    len -= n;
    80002bfe:	8c81                	sub	s1,s1,s0
    memmove((void*)dstva, src, n);
    80002c00:	796020ef          	jal	80005396 <memmove>
    src += n;
    80002c04:	99a2                	add	s3,s3,s0
    dstva += n;
    80002c06:	9922                	add	s2,s2,s0
  while(len > 0){
    80002c08:	f0fd                	bnez	s1,80002bee <copyout+0x18>
  }
  return 0;
}
    80002c0a:	70a2                	ld	ra,40(sp)
    80002c0c:	7402                	ld	s0,32(sp)
    80002c0e:	64e2                	ld	s1,24(sp)
    80002c10:	6942                	ld	s2,16(sp)
    80002c12:	69a2                	ld	s3,8(sp)
    80002c14:	6a02                	ld	s4,0(sp)
    80002c16:	4501                	li	a0,0
    80002c18:	6145                	add	sp,sp,48
    80002c1a:	8082                	ret
    80002c1c:	4501                	li	a0,0
    80002c1e:	8082                	ret

0000000080002c20 <copyin>:
// 从用户空间复制数据到内核空间
int copyin(pagetable_t pagetable, char *dst, uint64 srcva, uint64 len) {
  uint64 va0, pa0;
  pte_t *pte;
  
  while(len > 0){
    80002c20:	cac1                	beqz	a3,80002cb0 <copyin+0x90>
int copyin(pagetable_t pagetable, char *dst, uint64 srcva, uint64 len) {
    80002c22:	715d                	add	sp,sp,-80
    80002c24:	e0a2                	sd	s0,64(sp)
    80002c26:	f44e                	sd	s3,40(sp)
    80002c28:	f052                	sd	s4,32(sp)
    80002c2a:	ec56                	sd	s5,24(sp)
    80002c2c:	e85a                	sd	s6,16(sp)
    80002c2e:	e45e                	sd	s7,8(sp)
    80002c30:	e062                	sd	s8,0(sp)
    80002c32:	e486                	sd	ra,72(sp)
    80002c34:	fc26                	sd	s1,56(sp)
    80002c36:	f84a                	sd	s2,48(sp)
    80002c38:	8c36                	mv	s8,a3
    80002c3a:	8aaa                	mv	s5,a0
    80002c3c:	89ae                	mv	s3,a1
    80002c3e:	8432                	mv	s0,a2
    va0 = PGROUNDDOWN(srcva);
    80002c40:	7b7d                	lui	s6,0xfffff
    pte = walk_lookup(pagetable, va0);
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002c42:	4bc5                	li	s7,17
      return -1;
    pa0 = PTE2PA(*pte);
    uint64 n = PGSIZE - (srcva - va0);
    80002c44:	6a05                	lui	s4,0x1
    80002c46:	a03d                	j	80002c74 <copyin+0x54>
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002c48:	639c                	ld	a5,0(a5)
    if(n > len)
      n = len;
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    len -= n;
    dst += n;
    srcva = va0 + PGSIZE;
    80002c4a:	01490433          	add	s0,s2,s4
    pa0 = PTE2PA(*pte);
    80002c4e:	00a7d713          	srl	a4,a5,0xa
    80002c52:	0732                	sll	a4,a4,0xc
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002c54:	8bc5                	and	a5,a5,17
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    80002c56:	95ba                	add	a1,a1,a4
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002c58:	03779d63          	bne	a5,s7,80002c92 <copyin+0x72>
    80002c5c:	009c7363          	bgeu	s8,s1,80002c62 <copyin+0x42>
    80002c60:	84e2                	mv	s1,s8
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    80002c62:	0004861b          	sext.w	a2,s1
    len -= n;
    80002c66:	409c0c33          	sub	s8,s8,s1
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    80002c6a:	72c020ef          	jal	80005396 <memmove>
    dst += n;
    80002c6e:	99a6                	add	s3,s3,s1
  while(len > 0){
    80002c70:	020c0e63          	beqz	s8,80002cac <copyin+0x8c>
    va0 = PGROUNDDOWN(srcva);
    80002c74:	01647933          	and	s2,s0,s6
    pte = walk_lookup(pagetable, va0);
    80002c78:	85ca                	mv	a1,s2
    80002c7a:	8556                	mv	a0,s5
    80002c7c:	8c8fe0ef          	jal	80000d44 <walk_lookup>
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    80002c80:	412405b3          	sub	a1,s0,s2
    pte = walk_lookup(pagetable, va0);
    80002c84:	87aa                	mv	a5,a0
    uint64 n = PGSIZE - (srcva - va0);
    80002c86:	40890433          	sub	s0,s2,s0
    memmove(dst, (void*)(pa0 + (srcva - va0)), n);
    80002c8a:	854e                	mv	a0,s3
    uint64 n = PGSIZE - (srcva - va0);
    80002c8c:	014404b3          	add	s1,s0,s4
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002c90:	ffc5                	bnez	a5,80002c48 <copyin+0x28>
      return -1;
    80002c92:	557d                	li	a0,-1
  }
  return 0;
}
    80002c94:	60a6                	ld	ra,72(sp)
    80002c96:	6406                	ld	s0,64(sp)
    80002c98:	74e2                	ld	s1,56(sp)
    80002c9a:	7942                	ld	s2,48(sp)
    80002c9c:	79a2                	ld	s3,40(sp)
    80002c9e:	7a02                	ld	s4,32(sp)
    80002ca0:	6ae2                	ld	s5,24(sp)
    80002ca2:	6b42                	ld	s6,16(sp)
    80002ca4:	6ba2                	ld	s7,8(sp)
    80002ca6:	6c02                	ld	s8,0(sp)
    80002ca8:	6161                	add	sp,sp,80
    80002caa:	8082                	ret
  return 0;
    80002cac:	4501                	li	a0,0
    80002cae:	b7dd                	j	80002c94 <copyin+0x74>
    80002cb0:	4501                	li	a0,0
}
    80002cb2:	8082                	ret

0000000080002cb4 <either_copyout>:
// Copy to either a user address, or kernel address,
// depending on usr_dst.
// Returns 0 on success, -1 on error.
int
either_copyout(int user_dst, uint64 dst, void *src, uint64 len)
{
    80002cb4:	7179                	add	sp,sp,-48
    80002cb6:	f022                	sd	s0,32(sp)
    80002cb8:	e84a                	sd	s2,16(sp)
    80002cba:	e44e                	sd	s3,8(sp)
    80002cbc:	f406                	sd	ra,40(sp)
    80002cbe:	ec26                	sd	s1,24(sp)
    80002cc0:	e052                	sd	s4,0(sp)
    80002cc2:	892e                	mv	s2,a1
    80002cc4:	89b2                	mv	s3,a2
    80002cc6:	8436                	mv	s0,a3
  struct proc *p = myproc();
  if(user_dst){
    80002cc8:	c915                	beqz	a0,80002cfc <either_copyout+0x48>
    n = len < PGSIZE ? len : PGSIZE;
    80002cca:	6a05                	lui	s4,0x1
  while(len > 0){
    80002ccc:	ce99                	beqz	a3,80002cea <either_copyout+0x36>
    memmove((void*)dstva, src, n);
    80002cce:	85ce                	mv	a1,s3
    80002cd0:	854a                	mv	a0,s2
    n = len < PGSIZE ? len : PGSIZE;
    80002cd2:	84a2                	mv	s1,s0
    80002cd4:	008a7363          	bgeu	s4,s0,80002cda <either_copyout+0x26>
    80002cd8:	6485                	lui	s1,0x1
    memmove((void*)dstva, src, n);
    80002cda:	0004861b          	sext.w	a2,s1
    len -= n;
    80002cde:	8c05                	sub	s0,s0,s1
    memmove((void*)dstva, src, n);
    80002ce0:	6b6020ef          	jal	80005396 <memmove>
    src += n;
    80002ce4:	99a6                	add	s3,s3,s1
    dstva += n;
    80002ce6:	9926                	add	s2,s2,s1
  while(len > 0){
    80002ce8:	f07d                	bnez	s0,80002cce <either_copyout+0x1a>
    return copyout(p->pagetable, dst, src, len);
  } else {
    memmove((char *)dst, src, len);
    return 0;
  }
}
    80002cea:	70a2                	ld	ra,40(sp)
    80002cec:	7402                	ld	s0,32(sp)
    80002cee:	64e2                	ld	s1,24(sp)
    80002cf0:	6942                	ld	s2,16(sp)
    80002cf2:	69a2                	ld	s3,8(sp)
    80002cf4:	6a02                	ld	s4,0(sp)
    80002cf6:	4501                	li	a0,0
    80002cf8:	6145                	add	sp,sp,48
    80002cfa:	8082                	ret
    memmove((char *)dst, src, len);
    80002cfc:	0006861b          	sext.w	a2,a3
    80002d00:	85ce                	mv	a1,s3
    80002d02:	854a                	mv	a0,s2
    80002d04:	692020ef          	jal	80005396 <memmove>
    return 0;
    80002d08:	b7cd                	j	80002cea <either_copyout+0x36>

0000000080002d0a <either_copyin>:
  return cpus[0].proc;
    80002d0a:	00004897          	auipc	a7,0x4
    80002d0e:	ace8b883          	ld	a7,-1330(a7) # 800067d8 <cpus>
// Returns 0 on success, -1 on error.
int
either_copyin(void *dst, int user_src, uint64 src, uint64 len)
{
  struct proc *p = myproc();
  if(user_src){
    80002d12:	c591                	beqz	a1,80002d1e <either_copyin+0x14>
    return copyin(p->pagetable, dst, src, len);
    80002d14:	882a                	mv	a6,a0
    80002d16:	0c88b503          	ld	a0,200(a7)
    80002d1a:	85c2                	mv	a1,a6
    80002d1c:	b711                	j	80002c20 <copyin>
  } else {
    memmove(dst, (char*)src, len);
    80002d1e:	87b2                	mv	a5,a2
{
    80002d20:	1141                	add	sp,sp,-16
    memmove(dst, (char*)src, len);
    80002d22:	0006861b          	sext.w	a2,a3
    80002d26:	85be                	mv	a1,a5
{
    80002d28:	e406                	sd	ra,8(sp)
    memmove(dst, (char*)src, len);
    80002d2a:	66c020ef          	jal	80005396 <memmove>
    return 0;
  }
}
    80002d2e:	60a2                	ld	ra,8(sp)
    80002d30:	4501                	li	a0,0
    80002d32:	0141                	add	sp,sp,16
    80002d34:	8082                	ret

0000000080002d36 <copyinstr>:
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
  uint64 va0, pa0;
  pte_t *pte;
  int got_null = 0;
  
  while(got_null == 0 && max > 0){
    80002d36:	c2e9                	beqz	a3,80002df8 <copyinstr+0xc2>
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
    80002d38:	715d                	add	sp,sp,-80
    80002d3a:	f84a                	sd	s2,48(sp)
    80002d3c:	f052                	sd	s4,32(sp)
    80002d3e:	797d                	lui	s2,0xfffff
    80002d40:	8a32                	mv	s4,a2
    80002d42:	fc26                	sd	s1,56(sp)
    80002d44:	e85a                	sd	s6,16(sp)
    80002d46:	84aa                	mv	s1,a0
    va0 = PGROUNDDOWN(srcva);
    80002d48:	012a7b33          	and	s6,s4,s2
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
    80002d4c:	ec56                	sd	s5,24(sp)
    pte = walk_lookup(pagetable, va0);
    80002d4e:	8526                	mv	a0,s1
    80002d50:	8aae                	mv	s5,a1
    80002d52:	85da                	mv	a1,s6
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
    80002d54:	e0a2                	sd	s0,64(sp)
    80002d56:	f44e                	sd	s3,40(sp)
    80002d58:	e45e                	sd	s7,8(sp)
    80002d5a:	e486                	sd	ra,72(sp)
    80002d5c:	8bb6                	mv	s7,a3
    80002d5e:	49c5                	li	s3,17
    80002d60:	6405                	lui	s0,0x1
    pte = walk_lookup(pagetable, va0);
    80002d62:	fe3fd0ef          	jal	80000d44 <walk_lookup>
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002d66:	c151                	beqz	a0,80002dea <copyinstr+0xb4>
    80002d68:	611c                	ld	a5,0(a0)
    80002d6a:	0117f713          	and	a4,a5,17
    80002d6e:	07371e63          	bne	a4,s3,80002dea <copyinstr+0xb4>
      return -1;
    pa0 = PTE2PA(*pte);
    uint64 n = PGSIZE - (srcva - va0);
    80002d72:	414b0533          	sub	a0,s6,s4
    80002d76:	9522                	add	a0,a0,s0
    80002d78:	00abf363          	bgeu	s7,a0,80002d7e <copyinstr+0x48>
    80002d7c:	855e                	mv	a0,s7
    pa0 = PTE2PA(*pte);
    80002d7e:	83a9                	srl	a5,a5,0xa
    80002d80:	07b2                	sll	a5,a5,0xc
    if(n > max)
      n = max;
    char *p = (char *)(pa0 + (srcva - va0));
    80002d82:	416a0a33          	sub	s4,s4,s6
    80002d86:	01478633          	add	a2,a5,s4
    while(n > 0){
    80002d8a:	c135                	beqz	a0,80002dee <copyinstr+0xb8>
    80002d8c:	87d6                	mv	a5,s5
    80002d8e:	41560633          	sub	a2,a2,s5
    80002d92:	9556                	add	a0,a0,s5
    80002d94:	a031                	j	80002da0 <copyinstr+0x6a>
      if(*p == '\0'){
        *dst = '\0';
        got_null = 1;
        break;
      } else {
        *dst = *p;
    80002d96:	00e78023          	sb	a4,0(a5)
      }
      --n;
      --max;
      p++;
      dst++;
    80002d9a:	0785                	add	a5,a5,1
    while(n > 0){
    80002d9c:	02a78663          	beq	a5,a0,80002dc8 <copyinstr+0x92>
      if(*p == '\0'){
    80002da0:	00c78733          	add	a4,a5,a2
    80002da4:	00074703          	lbu	a4,0(a4)
    80002da8:	883e                	mv	a6,a5
    80002daa:	f775                	bnez	a4,80002d96 <copyinstr+0x60>
        *dst = '\0';
    80002dac:	00078023          	sb	zero,0(a5)
    80002db0:	4501                	li	a0,0
  if(got_null){
    return 0;
  } else {
    return -1;
  }
}
    80002db2:	60a6                	ld	ra,72(sp)
    80002db4:	6406                	ld	s0,64(sp)
    80002db6:	74e2                	ld	s1,56(sp)
    80002db8:	7942                	ld	s2,48(sp)
    80002dba:	79a2                	ld	s3,40(sp)
    80002dbc:	7a02                	ld	s4,32(sp)
    80002dbe:	6ae2                	ld	s5,24(sp)
    80002dc0:	6b42                	ld	s6,16(sp)
    80002dc2:	6ba2                	ld	s7,8(sp)
    80002dc4:	6161                	add	sp,sp,80
    80002dc6:	8082                	ret
    80002dc8:	fffb8713          	add	a4,s7,-1
    80002dcc:	9756                	add	a4,a4,s5
      --max;
    80002dce:	41070bb3          	sub	s7,a4,a6
    srcva = va0 + PGSIZE;
    80002dd2:	008b0a33          	add	s4,s6,s0
  while(got_null == 0 && max > 0){
    80002dd6:	00e80a63          	beq	a6,a4,80002dea <copyinstr+0xb4>
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
    80002dda:	8abe                	mv	s5,a5
    va0 = PGROUNDDOWN(srcva);
    80002ddc:	012a7b33          	and	s6,s4,s2
    pte = walk_lookup(pagetable, va0);
    80002de0:	85da                	mv	a1,s6
    80002de2:	8526                	mv	a0,s1
    80002de4:	f61fd0ef          	jal	80000d44 <walk_lookup>
    if(pte == 0 || (*pte & PTE_V) == 0 || (*pte & PTE_U) == 0)
    80002de8:	f141                	bnez	a0,80002d68 <copyinstr+0x32>
      return -1;
    80002dea:	557d                	li	a0,-1
    80002dec:	b7d9                	j	80002db2 <copyinstr+0x7c>
    srcva = va0 + PGSIZE;
    80002dee:	6a05                	lui	s4,0x1
    80002df0:	87d6                	mv	a5,s5
    80002df2:	9a5a                	add	s4,s4,s6
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) {
    80002df4:	8abe                	mv	s5,a5
    80002df6:	b7dd                	j	80002ddc <copyinstr+0xa6>
        *dst = '\0';
    80002df8:	557d                	li	a0,-1
}
    80002dfa:	8082                	ret

0000000080002dfc <setkilled>:



// 设置进程为killed状态
void setkilled(struct proc *p) {
    80002dfc:	1141                	add	sp,sp,-16
    80002dfe:	e022                	sd	s0,0(sp)
    80002e00:	e406                	sd	ra,8(sp)
    80002e02:	842a                	mv	s0,a0
  acquire(&p->lock);
    80002e04:	a62ff0ef          	jal	80002066 <acquire>
  p->killed = 1;
    80002e08:	4785                	li	a5,1
    80002e0a:	d41c                	sw	a5,40(s0)
  release(&p->lock);
    80002e0c:	8522                	mv	a0,s0
}
    80002e0e:	6402                	ld	s0,0(sp)
    80002e10:	60a2                	ld	ra,8(sp)
    80002e12:	0141                	add	sp,sp,16
  release(&p->lock);
    80002e14:	af8ff06f          	j	8000210c <release>

0000000080002e18 <killed>:

// 检查进程是否被killed
int killed(struct proc *p) {
    80002e18:	1101                	add	sp,sp,-32
    80002e1a:	ec06                	sd	ra,24(sp)
    80002e1c:	e822                	sd	s0,16(sp)
    80002e1e:	e426                	sd	s1,8(sp)
    80002e20:	842a                	mv	s0,a0
  int k;
  
  acquire(&p->lock);
    80002e22:	a44ff0ef          	jal	80002066 <acquire>
  k = p->killed;
  release(&p->lock);
    80002e26:	8522                	mv	a0,s0
  k = p->killed;
    80002e28:	5404                	lw	s1,40(s0)
  release(&p->lock);
    80002e2a:	ae2ff0ef          	jal	8000210c <release>
  return k;
}
    80002e2e:	60e2                	ld	ra,24(sp)
    80002e30:	6442                	ld	s0,16(sp)
    80002e32:	8526                	mv	a0,s1
    80002e34:	64a2                	ld	s1,8(sp)
    80002e36:	6105                	add	sp,sp,32
    80002e38:	8082                	ret

0000000080002e3a <create_task_process>:

// 创建一个执行指定任务的进程
// 这个方法允许你为不同的进程设置不同的任务入口点
struct proc* create_task_process(void (*task_func)(void)) {
    80002e3a:	1101                	add	sp,sp,-32
    80002e3c:	e822                	sd	s0,16(sp)
    80002e3e:	e426                	sd	s1,8(sp)
    80002e40:	ec06                	sd	ra,24(sp)
    80002e42:	84aa                	mv	s1,a0
  struct proc *p;
  
  // 分配进程结构体
  if((p = allocproc()) == 0) {
    80002e44:	d52ff0ef          	jal	80002396 <allocproc>
    80002e48:	842a                	mv	s0,a0
    80002e4a:	cd01                	beqz	a0,80002e62 <create_task_process+0x28>
    return 0;
  }
  
  // 设置任务入口点（覆盖默认的forkret）
  p->context.ra = (uint64)task_func;
    80002e4c:	e524                	sd	s1,72(a0)
  
  // 释放allocproc时获取的锁
  release(&p->lock);
    80002e4e:	abeff0ef          	jal	8000210c <release>
  
  // 设置为可运行状态
  acquire(&p->lock);
    80002e52:	8522                	mv	a0,s0
    80002e54:	a12ff0ef          	jal	80002066 <acquire>
  p->state = RUNNABLE;
    80002e58:	478d                	li	a5,3
    80002e5a:	cc1c                	sw	a5,24(s0)
  release(&p->lock);
    80002e5c:	8522                	mv	a0,s0
    80002e5e:	aaeff0ef          	jal	8000210c <release>
  return p;
}
    80002e62:	60e2                	ld	ra,24(sp)
    80002e64:	8522                	mv	a0,s0
    80002e66:	6442                	ld	s0,16(sp)
    80002e68:	64a2                	ld	s1,8(sp)
    80002e6a:	6105                	add	sp,sp,32
    80002e6c:	8082                	ret

0000000080002e6e <test_userProcess>:

void test_userProcess(void) {
    80002e6e:	1141                	add	sp,sp,-16
    80002e70:	e406                	sd	ra,8(sp)
    80002e72:	e022                	sd	s0,0(sp)
  struct proc *p = allocproc();
    80002e74:	d22ff0ef          	jal	80002396 <allocproc>
  printf("userProcess: %d\n", p->pid);
    80002e78:	590c                	lw	a1,48(a0)
  struct proc *p = allocproc();
    80002e7a:	842a                	mv	s0,a0
  printf("userProcess: %d\n", p->pid);
    80002e7c:	00003517          	auipc	a0,0x3
    80002e80:	3ac50513          	add	a0,a0,940 # 80006228 <syscalls+0x278>
    80002e84:	d02fd0ef          	jal	80000386 <printf>
  p->state = RUNNABLE;
    80002e88:	478d                	li	a5,3
  //fork();
  //exit(0);
}
    80002e8a:	60a2                	ld	ra,8(sp)
  p->state = RUNNABLE;
    80002e8c:	cc1c                	sw	a5,24(s0)
}
    80002e8e:	6402                	ld	s0,0(sp)
    80002e90:	0141                	add	sp,sp,16
    80002e92:	8082                	ret

0000000080002e94 <simple_task>:



// 简单的测试任务：只打印一些信息然后退出
void simple_task(void) {
    80002e94:	1101                	add	sp,sp,-32
    80002e96:	e822                	sd	s0,16(sp)
  return cpus[0].proc;
    80002e98:	00004417          	auipc	s0,0x4
    80002e9c:	94040413          	add	s0,s0,-1728 # 800067d8 <cpus>
void simple_task(void) {
    80002ea0:	e426                	sd	s1,8(sp)
  return cpus[0].proc;
    80002ea2:	6004                	ld	s1,0(s0)
void simple_task(void) {
    80002ea4:	ec06                	sd	ra,24(sp)
  struct proc *p = myproc();
  
  release(&p->lock);
    80002ea6:	8526                	mv	a0,s1
    80002ea8:	a64ff0ef          	jal	8000210c <release>
  
  printf("Process %d: Simple task started\n", p->pid);
    80002eac:	588c                	lw	a1,48(s1)
    80002eae:	00003517          	auipc	a0,0x3
    80002eb2:	39250513          	add	a0,a0,914 # 80006240 <syscalls+0x290>
    80002eb6:	cd0fd0ef          	jal	80000386 <printf>
  return cpus[0].proc;
    80002eba:	6000                	ld	s0,0(s0)
  acquire(&p->lock);
    80002ebc:	8522                	mv	a0,s0
    80002ebe:	9a8ff0ef          	jal	80002066 <acquire>
  p->state = RUNNABLE;
    80002ec2:	478d                	li	a5,3
    80002ec4:	cc1c                	sw	a5,24(s0)
  sched();
    80002ec6:	847ff0ef          	jal	8000270c <sched>
  release(&p->lock);
    80002eca:	8522                	mv	a0,s0
    80002ecc:	a40ff0ef          	jal	8000210c <release>
  yield();
  exit(0);
}
    80002ed0:	6442                	ld	s0,16(sp)
    80002ed2:	60e2                	ld	ra,24(sp)
    80002ed4:	64a2                	ld	s1,8(sp)
  exit(0);
    80002ed6:	4501                	li	a0,0
}
    80002ed8:	6105                	add	sp,sp,32
  exit(0);
    80002eda:	bcdd                	j	800029d0 <exit>

0000000080002edc <swtch>:
# Switches kernel stack

.globl swtch
swtch:
        # 保存旧进程的callee-saved寄存器到old context
        sd ra, 0(a0)   # 返回地址
    80002edc:	00153023          	sd	ra,0(a0)
        sd sp, 8(a0)   # 栈指针
    80002ee0:	00253423          	sd	sp,8(a0)
        sd s0, 16(a0)  # 保存s0-s11
    80002ee4:	e900                	sd	s0,16(a0)
        sd s1, 24(a0)
    80002ee6:	ed04                	sd	s1,24(a0)
        sd s2, 32(a0)
    80002ee8:	03253023          	sd	s2,32(a0)
        sd s3, 40(a0)
    80002eec:	03353423          	sd	s3,40(a0)
        sd s4, 48(a0)
    80002ef0:	03453823          	sd	s4,48(a0)
        sd s5, 56(a0)
    80002ef4:	03553c23          	sd	s5,56(a0)
        sd s6, 64(a0)
    80002ef8:	05653023          	sd	s6,64(a0)
        sd s7, 72(a0)
    80002efc:	05753423          	sd	s7,72(a0)
        sd s8, 80(a0)
    80002f00:	05853823          	sd	s8,80(a0)
        sd s9, 88(a0)
    80002f04:	05953c23          	sd	s9,88(a0)
        sd s10, 96(a0)
    80002f08:	07a53023          	sd	s10,96(a0)
        sd s11, 104(a0)
    80002f0c:	07b53423          	sd	s11,104(a0)

        # 从new context恢复寄存器
        ld ra, 0(a1)   # 加载新进程的返回地址
    80002f10:	0005b083          	ld	ra,0(a1)
        ld sp, 8(a1)   # 加载新进程的栈指针
    80002f14:	0085b103          	ld	sp,8(a1)
        ld s0, 16(a1)  # 恢复s0-s11
    80002f18:	6980                	ld	s0,16(a1)
        ld s1, 24(a1)
    80002f1a:	6d84                	ld	s1,24(a1)
        ld s2, 32(a1)
    80002f1c:	0205b903          	ld	s2,32(a1)
        ld s3, 40(a1)
    80002f20:	0285b983          	ld	s3,40(a1)
        ld s4, 48(a1)
    80002f24:	0305ba03          	ld	s4,48(a1)
        ld s5, 56(a1)
    80002f28:	0385ba83          	ld	s5,56(a1)
        ld s6, 64(a1)
    80002f2c:	0405bb03          	ld	s6,64(a1)
        ld s7, 72(a1)
    80002f30:	0485bb83          	ld	s7,72(a1)
        ld s8, 80(a1)
    80002f34:	0505bc03          	ld	s8,80(a1)
        ld s9, 88(a1)
    80002f38:	0585bc83          	ld	s9,88(a1)
        ld s10, 96(a1)
    80002f3c:	0605bd03          	ld	s10,96(a1)
        ld s11, 104(a1)
    80002f40:	0685bd83          	ld	s11,104(a1)

        ret            # 返回到新进程的ra（返回地址）
    80002f44:	8082                	ret

0000000080002f46 <flags2perm>:
#include "exec.h"

// map ELF permissions to PTE permission bits.
int flags2perm(int flags)
{
    80002f46:	1141                	add	sp,sp,-16
    80002f48:	e422                	sd	s0,8(sp)
    80002f4a:	0800                	add	s0,sp,16
    80002f4c:	87aa                	mv	a5,a0
    int perm = 0;
    if(flags & 0x1)
    80002f4e:	8905                	and	a0,a0,1
    80002f50:	050e                	sll	a0,a0,0x3
      perm = PTE_X;
    if(flags & 0x2)
    80002f52:	8b89                	and	a5,a5,2
    80002f54:	c399                	beqz	a5,80002f5a <flags2perm+0x14>
      perm |= PTE_W;
    80002f56:	00456513          	or	a0,a0,4
    return perm;
}
    80002f5a:	6422                	ld	s0,8(sp)
    80002f5c:	0141                	add	sp,sp,16
    80002f5e:	8082                	ret

0000000080002f60 <loadseg>:
{
  uint32  i, n;
  uint64 pa;
  pte_t *pte;

  for(i = 0; i < sz; i += PGSIZE){
    80002f60:	cb49                	beqz	a4,80002ff2 <loadseg+0x92>
{
    80002f62:	7159                	add	sp,sp,-112
    80002f64:	f486                	sd	ra,104(sp)
    80002f66:	f0a2                	sd	s0,96(sp)
    80002f68:	eca6                	sd	s1,88(sp)
    80002f6a:	e8ca                	sd	s2,80(sp)
    80002f6c:	e4ce                	sd	s3,72(sp)
    80002f6e:	e0d2                	sd	s4,64(sp)
    80002f70:	fc56                	sd	s5,56(sp)
    80002f72:	f85a                	sd	s6,48(sp)
    80002f74:	f45e                	sd	s7,40(sp)
    80002f76:	f062                	sd	s8,32(sp)
    80002f78:	ec66                	sd	s9,24(sp)
    80002f7a:	e86a                	sd	s10,16(sp)
    80002f7c:	e46e                	sd	s11,8(sp)
    80002f7e:	1880                	add	s0,sp,112
    80002f80:	8b2a                	mv	s6,a0
    80002f82:	8bae                	mv	s7,a1
    80002f84:	8c32                	mv	s8,a2
    80002f86:	8cb6                	mv	s9,a3
    80002f88:	8a3a                	mv	s4,a4
  for(i = 0; i < sz; i += PGSIZE){
    80002f8a:	4901                	li	s2,0
    pte = walk_lookup(pagetable, va + i);
    if(pte == 0 || (*pte & PTE_V) == 0)
      panic("loadseg: address should exist");
    80002f8c:	00003d97          	auipc	s11,0x3
    80002f90:	2dcd8d93          	add	s11,s11,732 # 80006268 <syscalls+0x2b8>
    pa = PTE2PA(*pte);
    if(sz - i < PGSIZE)
    80002f94:	6d05                	lui	s10,0x1
    80002f96:	6a85                	lui	s5,0x1
    80002f98:	a835                	j	80002fd4 <loadseg+0x74>
      panic("loadseg: address should exist");
    80002f9a:	856e                	mv	a0,s11
    80002f9c:	a05fd0ef          	jal	800009a0 <panic>
    if(sz - i < PGSIZE)
    80002fa0:	412a04bb          	subw	s1,s4,s2
    80002fa4:	0004879b          	sext.w	a5,s1
    80002fa8:	00fd7363          	bgeu	s10,a5,80002fae <loadseg+0x4e>
    80002fac:	84d6                	mv	s1,s5
    80002fae:	2481                	sext.w	s1,s1
    pa = PTE2PA(*pte);
    80002fb0:	0009b603          	ld	a2,0(s3)
    80002fb4:	8229                	srl	a2,a2,0xa
      n = sz - i;
    else
      n = PGSIZE;
    if(readi(ip, 0, (uint64)pa, offset+i, n) != n)
    80002fb6:	8726                	mv	a4,s1
    80002fb8:	012c86bb          	addw	a3,s9,s2
    80002fbc:	0632                	sll	a2,a2,0xc
    80002fbe:	4581                	li	a1,0
    80002fc0:	8562                	mv	a0,s8
    80002fc2:	19a010ef          	jal	8000415c <readi>
    80002fc6:	2501                	sext.w	a0,a0
    80002fc8:	02951763          	bne	a0,s1,80002ff6 <loadseg+0x96>
  for(i = 0; i < sz; i += PGSIZE){
    80002fcc:	012a893b          	addw	s2,s5,s2
    80002fd0:	01497f63          	bgeu	s2,s4,80002fee <loadseg+0x8e>
    pte = walk_lookup(pagetable, va + i);
    80002fd4:	02091593          	sll	a1,s2,0x20
    80002fd8:	9181                	srl	a1,a1,0x20
    80002fda:	95de                	add	a1,a1,s7
    80002fdc:	855a                	mv	a0,s6
    80002fde:	d67fd0ef          	jal	80000d44 <walk_lookup>
    80002fe2:	89aa                	mv	s3,a0
    if(pte == 0 || (*pte & PTE_V) == 0)
    80002fe4:	d95d                	beqz	a0,80002f9a <loadseg+0x3a>
    80002fe6:	611c                	ld	a5,0(a0)
    80002fe8:	8b85                	and	a5,a5,1
    80002fea:	fbdd                	bnez	a5,80002fa0 <loadseg+0x40>
    80002fec:	b77d                	j	80002f9a <loadseg+0x3a>
      return -1;
  }
  
  return 0;
    80002fee:	4501                	li	a0,0
    80002ff0:	a021                	j	80002ff8 <loadseg+0x98>
    80002ff2:	4501                	li	a0,0
}
    80002ff4:	8082                	ret
      return -1;
    80002ff6:	557d                	li	a0,-1
}
    80002ff8:	70a6                	ld	ra,104(sp)
    80002ffa:	7406                	ld	s0,96(sp)
    80002ffc:	64e6                	ld	s1,88(sp)
    80002ffe:	6946                	ld	s2,80(sp)
    80003000:	69a6                	ld	s3,72(sp)
    80003002:	6a06                	ld	s4,64(sp)
    80003004:	7ae2                	ld	s5,56(sp)
    80003006:	7b42                	ld	s6,48(sp)
    80003008:	7ba2                	ld	s7,40(sp)
    8000300a:	7c02                	ld	s8,32(sp)
    8000300c:	6ce2                	ld	s9,24(sp)
    8000300e:	6d42                	ld	s10,16(sp)
    80003010:	6da2                	ld	s11,8(sp)
    80003012:	6165                	add	sp,sp,112
    80003014:	8082                	ret

0000000080003016 <kexec>:
{
    80003016:	7101                	add	sp,sp,-512
    80003018:	ff86                	sd	ra,504(sp)
    8000301a:	fba2                	sd	s0,496(sp)
    8000301c:	f7a6                	sd	s1,488(sp)
    8000301e:	f3ca                	sd	s2,480(sp)
    80003020:	efce                	sd	s3,472(sp)
    80003022:	ebd2                	sd	s4,464(sp)
    80003024:	e7d6                	sd	s5,456(sp)
    80003026:	e3da                	sd	s6,448(sp)
    80003028:	ff5e                	sd	s7,440(sp)
    8000302a:	fb62                	sd	s8,432(sp)
    8000302c:	f766                	sd	s9,424(sp)
    8000302e:	f36a                	sd	s10,416(sp)
    80003030:	ef6e                	sd	s11,408(sp)
    80003032:	0400                	add	s0,sp,512
    80003034:	84aa                	mv	s1,a0
    80003036:	892e                	mv	s2,a1
  struct proc *p = myproc();
    80003038:	d2aff0ef          	jal	80002562 <myproc>
    8000303c:	89aa                	mv	s3,a0
  begin_op();
    8000303e:	0aa020ef          	jal	800050e8 <begin_op>
  if((ip = namei(path)) == 0){
    80003042:	8526                	mv	a0,s1
    80003044:	5be010ef          	jal	80004602 <namei>
    80003048:	cd39                	beqz	a0,800030a6 <kexec+0x90>
    8000304a:	8b2a                	mv	s6,a0
  ilock(ip);
    8000304c:	4cb000ef          	jal	80003d16 <ilock>
  if(readi(ip, 0, (uint64)&elf, 0, sizeof(elf)) != sizeof(elf))
    80003050:	04000713          	li	a4,64
    80003054:	4681                	li	a3,0
    80003056:	e5040613          	add	a2,s0,-432
    8000305a:	4581                	li	a1,0
    8000305c:	855a                	mv	a0,s6
    8000305e:	0fe010ef          	jal	8000415c <readi>
    80003062:	04000793          	li	a5,64
    80003066:	00f51a63          	bne	a0,a5,8000307a <kexec+0x64>
  if(elf.magic != ELF_MAGIC)
    8000306a:	e5042703          	lw	a4,-432(s0)
    8000306e:	464c47b7          	lui	a5,0x464c4
    80003072:	57f78793          	add	a5,a5,1407 # 464c457f <_entry-0x39b3ba81>
    80003076:	02f70c63          	beq	a4,a5,800030ae <kexec+0x98>
    iunlockput(ip);
    8000307a:	855a                	mv	a0,s6
    8000307c:	773000ef          	jal	80003fee <iunlockput>
    end_op();
    80003080:	0d2020ef          	jal	80005152 <end_op>
  return -1;
    80003084:	557d                	li	a0,-1
}
    80003086:	70fe                	ld	ra,504(sp)
    80003088:	745e                	ld	s0,496(sp)
    8000308a:	74be                	ld	s1,488(sp)
    8000308c:	791e                	ld	s2,480(sp)
    8000308e:	69fe                	ld	s3,472(sp)
    80003090:	6a5e                	ld	s4,464(sp)
    80003092:	6abe                	ld	s5,456(sp)
    80003094:	6b1e                	ld	s6,448(sp)
    80003096:	7bfa                	ld	s7,440(sp)
    80003098:	7c5a                	ld	s8,432(sp)
    8000309a:	7cba                	ld	s9,424(sp)
    8000309c:	7d1a                	ld	s10,416(sp)
    8000309e:	6dfa                	ld	s11,408(sp)
    800030a0:	20010113          	add	sp,sp,512
    800030a4:	8082                	ret
    end_op();
    800030a6:	0ac020ef          	jal	80005152 <end_op>
    return -1;
    800030aa:	557d                	li	a0,-1
    800030ac:	bfe9                	j	80003086 <kexec+0x70>
  if((pagetable = proc_pagetable(p)) == 0)
    800030ae:	854e                	mv	a0,s3
    800030b0:	a84ff0ef          	jal	80002334 <proc_pagetable>
    800030b4:	89aa                	mv	s3,a0
    800030b6:	d171                	beqz	a0,8000307a <kexec+0x64>
  for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
    800030b8:	e7042a03          	lw	s4,-400(s0)
    800030bc:	e8845783          	lhu	a5,-376(s0)
    800030c0:	cbc1                	beqz	a5,80003150 <kexec+0x13a>
  uint64 argc, sz = 0, sp, ustack[MAXARG], stackbase;
    800030c2:	4a81                	li	s5,0
  for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
    800030c4:	4c01                	li	s8,0
    if(ph.type != ELF_PROG_LOAD)
    800030c6:	4c85                	li	s9,1
    if(ph.vaddr % PGSIZE != 0)
    800030c8:	6d05                	lui	s10,0x1
    800030ca:	1d7d                	add	s10,s10,-1 # fff <_entry-0x7ffff001>
    800030cc:	a801                	j	800030dc <kexec+0xc6>
  for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
    800030ce:	2c05                	addw	s8,s8,1
    800030d0:	038a0a1b          	addw	s4,s4,56 # 1038 <_entry-0x7fffefc8>
    800030d4:	e8845783          	lhu	a5,-376(s0)
    800030d8:	06fc5d63          	bge	s8,a5,80003152 <kexec+0x13c>
    if(readi(ip, 0, (uint64)&ph, off, sizeof(ph)) != sizeof(ph))
    800030dc:	2a01                	sext.w	s4,s4
    800030de:	03800713          	li	a4,56
    800030e2:	86d2                	mv	a3,s4
    800030e4:	e1840613          	add	a2,s0,-488
    800030e8:	4581                	li	a1,0
    800030ea:	855a                	mv	a0,s6
    800030ec:	070010ef          	jal	8000415c <readi>
    800030f0:	03800793          	li	a5,56
    800030f4:	08f51b63          	bne	a0,a5,8000318a <kexec+0x174>
    if(ph.type != ELF_PROG_LOAD)
    800030f8:	e1842783          	lw	a5,-488(s0)
    800030fc:	fd9799e3          	bne	a5,s9,800030ce <kexec+0xb8>
    if(ph.memsz < ph.filesz)
    80003100:	e4043b83          	ld	s7,-448(s0)
    80003104:	e3843783          	ld	a5,-456(s0)
    80003108:	08fbe163          	bltu	s7,a5,8000318a <kexec+0x174>
    if(ph.vaddr + ph.memsz < ph.vaddr)
    8000310c:	e2843783          	ld	a5,-472(s0)
    80003110:	9bbe                	add	s7,s7,a5
    80003112:	06fbec63          	bltu	s7,a5,8000318a <kexec+0x174>
    if(ph.vaddr % PGSIZE != 0)
    80003116:	01a7f7b3          	and	a5,a5,s10
    8000311a:	eba5                	bnez	a5,8000318a <kexec+0x174>
    if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz, flags2perm(ph.flags))) == 0)
    8000311c:	e1c42503          	lw	a0,-484(s0)
    80003120:	e27ff0ef          	jal	80002f46 <flags2perm>
    80003124:	86aa                	mv	a3,a0
    80003126:	865e                	mv	a2,s7
    80003128:	85d6                	mv	a1,s5
    8000312a:	854e                	mv	a0,s3
    8000312c:	e71fd0ef          	jal	80000f9c <uvmalloc>
    80003130:	8baa                	mv	s7,a0
    80003132:	cd21                	beqz	a0,8000318a <kexec+0x174>
    if(loadseg(pagetable, ph.vaddr, ip, ph.off, ph.filesz) < 0)
    80003134:	e3842703          	lw	a4,-456(s0)
    80003138:	e2042683          	lw	a3,-480(s0)
    8000313c:	865a                	mv	a2,s6
    8000313e:	e2843583          	ld	a1,-472(s0)
    80003142:	854e                	mv	a0,s3
    80003144:	e1dff0ef          	jal	80002f60 <loadseg>
    80003148:	14054763          	bltz	a0,80003296 <kexec+0x280>
    if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz, flags2perm(ph.flags))) == 0)
    8000314c:	8ade                	mv	s5,s7
    8000314e:	b741                	j	800030ce <kexec+0xb8>
  uint64 argc, sz = 0, sp, ustack[MAXARG], stackbase;
    80003150:	4a81                	li	s5,0
  iunlockput(ip);
    80003152:	855a                	mv	a0,s6
    80003154:	69b000ef          	jal	80003fee <iunlockput>
  end_op();
    80003158:	7fb010ef          	jal	80005152 <end_op>
  p = myproc();
    8000315c:	c06ff0ef          	jal	80002562 <myproc>
    80003160:	8d2a                	mv	s10,a0
  uint64 oldsz = p->sz;
    80003162:	617c                	ld	a5,192(a0)
    80003164:	e0f43423          	sd	a5,-504(s0)
  sz = PGROUNDUP(sz);
    80003168:	6b05                	lui	s6,0x1
    8000316a:	1b7d                	add	s6,s6,-1 # fff <_entry-0x7ffff001>
    8000316c:	9b56                	add	s6,s6,s5
    8000316e:	77fd                	lui	a5,0xfffff
    80003170:	00fb7b33          	and	s6,s6,a5
  if((sz1 = uvmalloc(pagetable, sz, sz + (USERSTACK+1)*PGSIZE, PTE_W)) == 0)
    80003174:	4691                	li	a3,4
    80003176:	6609                	lui	a2,0x2
    80003178:	965a                	add	a2,a2,s6
    8000317a:	85da                	mv	a1,s6
    8000317c:	854e                	mv	a0,s3
    8000317e:	e1ffd0ef          	jal	80000f9c <uvmalloc>
    80003182:	8aaa                	mv	s5,a0
    80003184:	e919                	bnez	a0,8000319a <kexec+0x184>
    if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz, flags2perm(ph.flags))) == 0)
    80003186:	8ada                	mv	s5,s6
    80003188:	4b01                	li	s6,0
    proc_freepagetable(pagetable, sz);
    8000318a:	85d6                	mv	a1,s5
    8000318c:	854e                	mv	a0,s3
    8000318e:	b94ff0ef          	jal	80002522 <proc_freepagetable>
  return -1;
    80003192:	557d                	li	a0,-1
  if(ip){
    80003194:	ee0b09e3          	beqz	s6,80003086 <kexec+0x70>
    80003198:	b5cd                	j	8000307a <kexec+0x64>
  uvmclear(pagetable, sz-(USERSTACK+1)*PGSIZE);
    8000319a:	75f9                	lui	a1,0xffffe
    8000319c:	95aa                	add	a1,a1,a0
    8000319e:	854e                	mv	a0,s3
    800031a0:	e9ffd0ef          	jal	8000103e <uvmclear>
  stackbase = sp - USERSTACK*PGSIZE;
    800031a4:	7cfd                	lui	s9,0xfffff
    800031a6:	9cd6                	add	s9,s9,s5
  for(argc = 0; argv[argc]; argc++) {
    800031a8:	00093503          	ld	a0,0(s2) # fffffffffffff000 <stack_top+0xffffffff7ffe4ff0>
    800031ac:	c931                	beqz	a0,80003200 <kexec+0x1ea>
    800031ae:	e9040b93          	add	s7,s0,-368
    800031b2:	f9040d93          	add	s11,s0,-112
  sp = sz;
    800031b6:	8b56                	mv	s6,s5
  for(argc = 0; argv[argc]; argc++) {
    800031b8:	4a01                	li	s4,0
    sp -= strlen(argv[argc]) + 1;
    800031ba:	2f6020ef          	jal	800054b0 <strlen>
    800031be:	2505                	addw	a0,a0,1
    800031c0:	40ab0533          	sub	a0,s6,a0
    sp -= sp % 16; // riscv sp must be 16-byte aligned
    800031c4:	ff057b13          	and	s6,a0,-16
    if(sp < stackbase)
    800031c8:	0d9b6963          	bltu	s6,s9,8000329a <kexec+0x284>
    if(copyout(pagetable, sp, argv[argc], strlen(argv[argc]) + 1) < 0)
    800031cc:	00093c03          	ld	s8,0(s2)
    800031d0:	8562                	mv	a0,s8
    800031d2:	2de020ef          	jal	800054b0 <strlen>
    800031d6:	0015069b          	addw	a3,a0,1
    800031da:	8662                	mv	a2,s8
    800031dc:	85da                	mv	a1,s6
    800031de:	854e                	mv	a0,s3
    800031e0:	9f7ff0ef          	jal	80002bd6 <copyout>
    800031e4:	0a054d63          	bltz	a0,8000329e <kexec+0x288>
    ustack[argc] = sp;
    800031e8:	016bb023          	sd	s6,0(s7)
  for(argc = 0; argv[argc]; argc++) {
    800031ec:	0a05                	add	s4,s4,1
    800031ee:	0921                	add	s2,s2,8
    800031f0:	00093503          	ld	a0,0(s2)
    800031f4:	c901                	beqz	a0,80003204 <kexec+0x1ee>
    if(argc >= MAXARG)
    800031f6:	0ba1                	add	s7,s7,8
    800031f8:	fdbb91e3          	bne	s7,s11,800031ba <kexec+0x1a4>
  ip = 0;
    800031fc:	4b01                	li	s6,0
    800031fe:	b771                	j	8000318a <kexec+0x174>
  sp = sz;
    80003200:	8b56                	mv	s6,s5
  for(argc = 0; argv[argc]; argc++) {
    80003202:	4a01                	li	s4,0
  ustack[argc] = 0;
    80003204:	003a1793          	sll	a5,s4,0x3
    80003208:	f9078793          	add	a5,a5,-112 # ffffffffffffef90 <stack_top+0xffffffff7ffe4f80>
    8000320c:	97a2                	add	a5,a5,s0
    8000320e:	f007b023          	sd	zero,-256(a5)
  sp -= (argc+1) * sizeof(uint64);
    80003212:	001a0693          	add	a3,s4,1
    80003216:	068e                	sll	a3,a3,0x3
    80003218:	40db0933          	sub	s2,s6,a3
  sp -= sp % 16;
    8000321c:	ff097913          	and	s2,s2,-16
  sz = sz1;
    80003220:	8b56                	mv	s6,s5
  if(sp < stackbase)
    80003222:	f79962e3          	bltu	s2,s9,80003186 <kexec+0x170>
  if(copyout(pagetable, sp, (char *)ustack, (argc+1)*sizeof(uint64)) < 0)
    80003226:	e9040613          	add	a2,s0,-368
    8000322a:	85ca                	mv	a1,s2
    8000322c:	854e                	mv	a0,s3
    8000322e:	9a9ff0ef          	jal	80002bd6 <copyout>
    80003232:	f4054ae3          	bltz	a0,80003186 <kexec+0x170>
  p->trapframe->a1 = sp;
    80003236:	040d3783          	ld	a5,64(s10)
    8000323a:	0727bc23          	sd	s2,120(a5)
  for(last=s=path; *s; s++)
    8000323e:	0004c703          	lbu	a4,0(s1) # 1000 <_entry-0x7ffff000>
    80003242:	cf11                	beqz	a4,8000325e <kexec+0x248>
    80003244:	00148793          	add	a5,s1,1
    if(*s == '/')
    80003248:	02f00693          	li	a3,47
    8000324c:	a029                	j	80003256 <kexec+0x240>
  for(last=s=path; *s; s++)
    8000324e:	0785                	add	a5,a5,1
    80003250:	fff7c703          	lbu	a4,-1(a5)
    80003254:	c709                	beqz	a4,8000325e <kexec+0x248>
    if(*s == '/')
    80003256:	fed71ce3          	bne	a4,a3,8000324e <kexec+0x238>
      last = s+1;
    8000325a:	84be                	mv	s1,a5
    8000325c:	bfcd                	j	8000324e <kexec+0x238>
  safestrcpy(p->name, last, sizeof(p->name));
    8000325e:	4641                	li	a2,16
    80003260:	85a6                	mv	a1,s1
    80003262:	0d0d0513          	add	a0,s10,208
    80003266:	218020ef          	jal	8000547e <safestrcpy>
  oldpagetable = p->pagetable;
    8000326a:	0c8d3503          	ld	a0,200(s10)
  p->pagetable = pagetable;
    8000326e:	0d3d3423          	sd	s3,200(s10)
  p->sz = sz;
    80003272:	0d5d3023          	sd	s5,192(s10)
  p->trapframe->epc = elf.entry;  // initial program counter = ulib.c:start()
    80003276:	040d3783          	ld	a5,64(s10)
    8000327a:	e6843703          	ld	a4,-408(s0)
    8000327e:	ef98                	sd	a4,24(a5)
  p->trapframe->sp = sp; // initial stack pointer
    80003280:	040d3783          	ld	a5,64(s10)
    80003284:	0327b823          	sd	s2,48(a5)
  proc_freepagetable(oldpagetable, oldsz);
    80003288:	e0843583          	ld	a1,-504(s0)
    8000328c:	a96ff0ef          	jal	80002522 <proc_freepagetable>
  return argc; // this ends up in a0, the first argument to main(argc, argv)
    80003290:	000a051b          	sext.w	a0,s4
    80003294:	bbcd                	j	80003086 <kexec+0x70>
    if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz, flags2perm(ph.flags))) == 0)
    80003296:	8ade                	mv	s5,s7
    80003298:	bdcd                	j	8000318a <kexec+0x174>
  ip = 0;
    8000329a:	4b01                	li	s6,0
    8000329c:	b5fd                	j	8000318a <kexec+0x174>
    8000329e:	4b01                	li	s6,0
  if(pagetable)
    800032a0:	b5ed                	j	8000318a <kexec+0x174>

00000000800032a2 <binit>:

struct bcache bcache;

void
binit(void)
{
    800032a2:	7179                	add	sp,sp,-48
    800032a4:	f406                	sd	ra,40(sp)
    800032a6:	f022                	sd	s0,32(sp)
    800032a8:	ec26                	sd	s1,24(sp)
    800032aa:	e84a                	sd	s2,16(sp)
    800032ac:	e44e                	sd	s3,8(sp)
    800032ae:	e052                	sd	s4,0(sp)
    800032b0:	1800                	add	s0,sp,48
  struct buf *b;

  initlock(&bcache.lock, "bcache");
    800032b2:	00003597          	auipc	a1,0x3
    800032b6:	fd658593          	add	a1,a1,-42 # 80006288 <syscalls+0x2d8>
    800032ba:	00009517          	auipc	a0,0x9
    800032be:	fd650513          	add	a0,a0,-42 # 8000c290 <bcache>
    800032c2:	d43fe0ef          	jal	80002004 <initlock>

  // Create linked list of buffers
  bcache.head.prev = &bcache.head;
    800032c6:	00011797          	auipc	a5,0x11
    800032ca:	fca78793          	add	a5,a5,-54 # 80014290 <bcache+0x8000>
    800032ce:	00011717          	auipc	a4,0x11
    800032d2:	22a70713          	add	a4,a4,554 # 800144f8 <bcache+0x8268>
    800032d6:	2ae7b823          	sd	a4,688(a5)
  bcache.head.next = &bcache.head;
    800032da:	2ae7bc23          	sd	a4,696(a5)
  for(b = bcache.buf; b < bcache.buf+NBUF; b++){
    800032de:	00009497          	auipc	s1,0x9
    800032e2:	fca48493          	add	s1,s1,-54 # 8000c2a8 <bcache+0x18>
    b->next = bcache.head.next;
    800032e6:	893e                	mv	s2,a5
    b->prev = &bcache.head;
    800032e8:	89ba                	mv	s3,a4
    initsleeplock(&b->lock, "buffer");
    800032ea:	00003a17          	auipc	s4,0x3
    800032ee:	fa6a0a13          	add	s4,s4,-90 # 80006290 <syscalls+0x2e0>
    b->next = bcache.head.next;
    800032f2:	2b893783          	ld	a5,696(s2)
    800032f6:	e8bc                	sd	a5,80(s1)
    b->prev = &bcache.head;
    800032f8:	0534b423          	sd	s3,72(s1)
    initsleeplock(&b->lock, "buffer");
    800032fc:	85d2                	mv	a1,s4
    800032fe:	01048513          	add	a0,s1,16
    80003302:	332010ef          	jal	80004634 <initsleeplock>
    bcache.head.next->prev = b;
    80003306:	2b893783          	ld	a5,696(s2)
    8000330a:	e7a4                	sd	s1,72(a5)
    bcache.head.next = b;
    8000330c:	2a993c23          	sd	s1,696(s2)
  for(b = bcache.buf; b < bcache.buf+NBUF; b++){
    80003310:	45848493          	add	s1,s1,1112
    80003314:	fd349fe3          	bne	s1,s3,800032f2 <binit+0x50>
  }
}
    80003318:	70a2                	ld	ra,40(sp)
    8000331a:	7402                	ld	s0,32(sp)
    8000331c:	64e2                	ld	s1,24(sp)
    8000331e:	6942                	ld	s2,16(sp)
    80003320:	69a2                	ld	s3,8(sp)
    80003322:	6a02                	ld	s4,0(sp)
    80003324:	6145                	add	sp,sp,48
    80003326:	8082                	ret

0000000080003328 <bget>:
// Look through buffer cache for block on device dev.
// If not found, allocate a buffer.
// In either case, return locked buffer.
 struct buf*
bget(uint32 dev, uint32 blockno)
{
    80003328:	7179                	add	sp,sp,-48
    8000332a:	f406                	sd	ra,40(sp)
    8000332c:	f022                	sd	s0,32(sp)
    8000332e:	ec26                	sd	s1,24(sp)
    80003330:	e84a                	sd	s2,16(sp)
    80003332:	e44e                	sd	s3,8(sp)
    80003334:	1800                	add	s0,sp,48
    80003336:	892a                	mv	s2,a0
    80003338:	89ae                	mv	s3,a1
  struct buf *b;

  acquire(&bcache.lock);
    8000333a:	00009517          	auipc	a0,0x9
    8000333e:	f5650513          	add	a0,a0,-170 # 8000c290 <bcache>
    80003342:	d25fe0ef          	jal	80002066 <acquire>

  // Is the block already cached?
  for(b = bcache.head.next; b != &bcache.head; b = b->next){
    80003346:	00011497          	auipc	s1,0x11
    8000334a:	2024b483          	ld	s1,514(s1) # 80014548 <bcache+0x82b8>
    8000334e:	00011797          	auipc	a5,0x11
    80003352:	1aa78793          	add	a5,a5,426 # 800144f8 <bcache+0x8268>
    80003356:	02f48b63          	beq	s1,a5,8000338c <bget+0x64>
    8000335a:	873e                	mv	a4,a5
    8000335c:	a021                	j	80003364 <bget+0x3c>
    8000335e:	68a4                	ld	s1,80(s1)
    80003360:	02e48663          	beq	s1,a4,8000338c <bget+0x64>
    if(b->dev == dev && b->blockno == blockno){
    80003364:	449c                	lw	a5,8(s1)
    80003366:	ff279ce3          	bne	a5,s2,8000335e <bget+0x36>
    8000336a:	44dc                	lw	a5,12(s1)
    8000336c:	ff3799e3          	bne	a5,s3,8000335e <bget+0x36>
      b->refcnt++;
    80003370:	40bc                	lw	a5,64(s1)
    80003372:	2785                	addw	a5,a5,1
    80003374:	c0bc                	sw	a5,64(s1)
      release(&bcache.lock);
    80003376:	00009517          	auipc	a0,0x9
    8000337a:	f1a50513          	add	a0,a0,-230 # 8000c290 <bcache>
    8000337e:	d8ffe0ef          	jal	8000210c <release>
      acquiresleep(&b->lock);
    80003382:	01048513          	add	a0,s1,16
    80003386:	2e4010ef          	jal	8000466a <acquiresleep>
      return b;
    8000338a:	a805                	j	800033ba <bget+0x92>
    }
  }

  // Not cached.
  // Recycle the least recently used (LRU) unused buffer.
  for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
    8000338c:	00011497          	auipc	s1,0x11
    80003390:	1b44b483          	ld	s1,436(s1) # 80014540 <bcache+0x82b0>
    80003394:	00011797          	auipc	a5,0x11
    80003398:	16478793          	add	a5,a5,356 # 800144f8 <bcache+0x8268>
    8000339c:	00f48863          	beq	s1,a5,800033ac <bget+0x84>
    800033a0:	873e                	mv	a4,a5
    if(b->refcnt == 0) {
    800033a2:	40bc                	lw	a5,64(s1)
    800033a4:	c39d                	beqz	a5,800033ca <bget+0xa2>
  for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
    800033a6:	64a4                	ld	s1,72(s1)
    800033a8:	fee49de3          	bne	s1,a4,800033a2 <bget+0x7a>
      release(&bcache.lock);
      acquiresleep(&b->lock);
      return b;
    }
  }
  panic("bget: no buffers");
    800033ac:	00003517          	auipc	a0,0x3
    800033b0:	eec50513          	add	a0,a0,-276 # 80006298 <syscalls+0x2e8>
    800033b4:	decfd0ef          	jal	800009a0 <panic>
  return 0;
    800033b8:	4481                	li	s1,0
}
    800033ba:	8526                	mv	a0,s1
    800033bc:	70a2                	ld	ra,40(sp)
    800033be:	7402                	ld	s0,32(sp)
    800033c0:	64e2                	ld	s1,24(sp)
    800033c2:	6942                	ld	s2,16(sp)
    800033c4:	69a2                	ld	s3,8(sp)
    800033c6:	6145                	add	sp,sp,48
    800033c8:	8082                	ret
      b->dev = dev;
    800033ca:	0124a423          	sw	s2,8(s1)
      b->blockno = blockno;
    800033ce:	0134a623          	sw	s3,12(s1)
      b->valid = 0;
    800033d2:	0004a023          	sw	zero,0(s1)
      b->refcnt = 1;
    800033d6:	4785                	li	a5,1
    800033d8:	c0bc                	sw	a5,64(s1)
      release(&bcache.lock);
    800033da:	00009517          	auipc	a0,0x9
    800033de:	eb650513          	add	a0,a0,-330 # 8000c290 <bcache>
    800033e2:	d2bfe0ef          	jal	8000210c <release>
      acquiresleep(&b->lock);
    800033e6:	01048513          	add	a0,s1,16
    800033ea:	280010ef          	jal	8000466a <acquiresleep>
      return b;
    800033ee:	b7f1                	j	800033ba <bget+0x92>

00000000800033f0 <bread>:

// Return a locked buf with the contents of the indicated block.
struct buf*
bread(uint32 dev, uint32 blockno)
{
    800033f0:	1101                	add	sp,sp,-32
    800033f2:	ec06                	sd	ra,24(sp)
    800033f4:	e822                	sd	s0,16(sp)
    800033f6:	e426                	sd	s1,8(sp)
    800033f8:	1000                	add	s0,sp,32
  struct buf *b;

  b = bget(dev, blockno);
    800033fa:	f2fff0ef          	jal	80003328 <bget>
    800033fe:	84aa                	mv	s1,a0
  if(!b->valid) {
    80003400:	411c                	lw	a5,0(a0)
    80003402:	c799                	beqz	a5,80003410 <bread+0x20>
    virtio_disk_rw(b, 0);
    b->valid = 1;
  }
  return b;
}
    80003404:	8526                	mv	a0,s1
    80003406:	60e2                	ld	ra,24(sp)
    80003408:	6442                	ld	s0,16(sp)
    8000340a:	64a2                	ld	s1,8(sp)
    8000340c:	6105                	add	sp,sp,32
    8000340e:	8082                	ret
    virtio_disk_rw(b, 0);
    80003410:	4581                	li	a1,0
    80003412:	632010ef          	jal	80004a44 <virtio_disk_rw>
    b->valid = 1;
    80003416:	4785                	li	a5,1
    80003418:	c09c                	sw	a5,0(s1)
  return b;
    8000341a:	b7ed                	j	80003404 <bread+0x14>

000000008000341c <bwrite>:

// Write b's contents to disk.  Must be locked.
void
bwrite(struct buf *b)
{
    8000341c:	1101                	add	sp,sp,-32
    8000341e:	ec06                	sd	ra,24(sp)
    80003420:	e822                	sd	s0,16(sp)
    80003422:	e426                	sd	s1,8(sp)
    80003424:	1000                	add	s0,sp,32
    80003426:	84aa                	mv	s1,a0
  if(!holdingsleep(&b->lock))
    80003428:	0541                	add	a0,a0,16
    8000342a:	2be010ef          	jal	800046e8 <holdingsleep>
    8000342e:	c911                	beqz	a0,80003442 <bwrite+0x26>
    panic("bwrite");
  virtio_disk_rw(b, 1);
    80003430:	4585                	li	a1,1
    80003432:	8526                	mv	a0,s1
    80003434:	610010ef          	jal	80004a44 <virtio_disk_rw>
}
    80003438:	60e2                	ld	ra,24(sp)
    8000343a:	6442                	ld	s0,16(sp)
    8000343c:	64a2                	ld	s1,8(sp)
    8000343e:	6105                	add	sp,sp,32
    80003440:	8082                	ret
    panic("bwrite");
    80003442:	00003517          	auipc	a0,0x3
    80003446:	e6e50513          	add	a0,a0,-402 # 800062b0 <syscalls+0x300>
    8000344a:	d56fd0ef          	jal	800009a0 <panic>
    8000344e:	b7cd                	j	80003430 <bwrite+0x14>

0000000080003450 <brelse>:

// Release a locked buffer.
// Move to the head of the most-recently-used list.
void
brelse(struct buf *b)
{
    80003450:	1101                	add	sp,sp,-32
    80003452:	ec06                	sd	ra,24(sp)
    80003454:	e822                	sd	s0,16(sp)
    80003456:	e426                	sd	s1,8(sp)
    80003458:	e04a                	sd	s2,0(sp)
    8000345a:	1000                	add	s0,sp,32
    8000345c:	84aa                	mv	s1,a0
  if(!holdingsleep(&b->lock))
    8000345e:	01050913          	add	s2,a0,16
    80003462:	854a                	mv	a0,s2
    80003464:	284010ef          	jal	800046e8 <holdingsleep>
    80003468:	c135                	beqz	a0,800034cc <brelse+0x7c>
    panic("brelse");

  releasesleep(&b->lock);
    8000346a:	854a                	mv	a0,s2
    8000346c:	244010ef          	jal	800046b0 <releasesleep>

  acquire(&bcache.lock);
    80003470:	00009517          	auipc	a0,0x9
    80003474:	e2050513          	add	a0,a0,-480 # 8000c290 <bcache>
    80003478:	beffe0ef          	jal	80002066 <acquire>
  b->refcnt--;
    8000347c:	40bc                	lw	a5,64(s1)
    8000347e:	37fd                	addw	a5,a5,-1
    80003480:	0007871b          	sext.w	a4,a5
    80003484:	c0bc                	sw	a5,64(s1)
  if (b->refcnt == 0) {
    80003486:	e71d                	bnez	a4,800034b4 <brelse+0x64>
    // no one is waiting for it.
    b->next->prev = b->prev;
    80003488:	68b8                	ld	a4,80(s1)
    8000348a:	64bc                	ld	a5,72(s1)
    8000348c:	e73c                	sd	a5,72(a4)
    b->prev->next = b->next;
    8000348e:	68b8                	ld	a4,80(s1)
    80003490:	ebb8                	sd	a4,80(a5)
    b->next = bcache.head.next;
    80003492:	00011797          	auipc	a5,0x11
    80003496:	dfe78793          	add	a5,a5,-514 # 80014290 <bcache+0x8000>
    8000349a:	2b87b703          	ld	a4,696(a5)
    8000349e:	e8b8                	sd	a4,80(s1)
    b->prev = &bcache.head;
    800034a0:	00011717          	auipc	a4,0x11
    800034a4:	05870713          	add	a4,a4,88 # 800144f8 <bcache+0x8268>
    800034a8:	e4b8                	sd	a4,72(s1)
    bcache.head.next->prev = b;
    800034aa:	2b87b703          	ld	a4,696(a5)
    800034ae:	e724                	sd	s1,72(a4)
    bcache.head.next = b;
    800034b0:	2a97bc23          	sd	s1,696(a5)
  }
  
  release(&bcache.lock);
    800034b4:	00009517          	auipc	a0,0x9
    800034b8:	ddc50513          	add	a0,a0,-548 # 8000c290 <bcache>
    800034bc:	c51fe0ef          	jal	8000210c <release>
}
    800034c0:	60e2                	ld	ra,24(sp)
    800034c2:	6442                	ld	s0,16(sp)
    800034c4:	64a2                	ld	s1,8(sp)
    800034c6:	6902                	ld	s2,0(sp)
    800034c8:	6105                	add	sp,sp,32
    800034ca:	8082                	ret
    panic("brelse");
    800034cc:	00003517          	auipc	a0,0x3
    800034d0:	dec50513          	add	a0,a0,-532 # 800062b8 <syscalls+0x308>
    800034d4:	cccfd0ef          	jal	800009a0 <panic>
    800034d8:	bf49                	j	8000346a <brelse+0x1a>

00000000800034da <bpin>:

void
bpin(struct buf *b) {
    800034da:	1101                	add	sp,sp,-32
    800034dc:	ec06                	sd	ra,24(sp)
    800034de:	e822                	sd	s0,16(sp)
    800034e0:	e426                	sd	s1,8(sp)
    800034e2:	1000                	add	s0,sp,32
    800034e4:	84aa                	mv	s1,a0
  acquire(&bcache.lock);
    800034e6:	00009517          	auipc	a0,0x9
    800034ea:	daa50513          	add	a0,a0,-598 # 8000c290 <bcache>
    800034ee:	b79fe0ef          	jal	80002066 <acquire>
  b->refcnt++;
    800034f2:	40bc                	lw	a5,64(s1)
    800034f4:	2785                	addw	a5,a5,1
    800034f6:	c0bc                	sw	a5,64(s1)
  release(&bcache.lock);
    800034f8:	00009517          	auipc	a0,0x9
    800034fc:	d9850513          	add	a0,a0,-616 # 8000c290 <bcache>
    80003500:	c0dfe0ef          	jal	8000210c <release>
}
    80003504:	60e2                	ld	ra,24(sp)
    80003506:	6442                	ld	s0,16(sp)
    80003508:	64a2                	ld	s1,8(sp)
    8000350a:	6105                	add	sp,sp,32
    8000350c:	8082                	ret

000000008000350e <bunpin>:

void
bunpin(struct buf *b) {
    8000350e:	1101                	add	sp,sp,-32
    80003510:	ec06                	sd	ra,24(sp)
    80003512:	e822                	sd	s0,16(sp)
    80003514:	e426                	sd	s1,8(sp)
    80003516:	1000                	add	s0,sp,32
    80003518:	84aa                	mv	s1,a0
  acquire(&bcache.lock);
    8000351a:	00009517          	auipc	a0,0x9
    8000351e:	d7650513          	add	a0,a0,-650 # 8000c290 <bcache>
    80003522:	b45fe0ef          	jal	80002066 <acquire>
  b->refcnt--;
    80003526:	40bc                	lw	a5,64(s1)
    80003528:	37fd                	addw	a5,a5,-1
    8000352a:	c0bc                	sw	a5,64(s1)
  release(&bcache.lock);
    8000352c:	00009517          	auipc	a0,0x9
    80003530:	d6450513          	add	a0,a0,-668 # 8000c290 <bcache>
    80003534:	bd9fe0ef          	jal	8000210c <release>
}
    80003538:	60e2                	ld	ra,24(sp)
    8000353a:	6442                	ld	s0,16(sp)
    8000353c:	64a2                	ld	s1,8(sp)
    8000353e:	6105                	add	sp,sp,32
    80003540:	8082                	ret

0000000080003542 <fileinit>:
struct filetable ftable;


void
fileinit(void)
{
    80003542:	1141                	add	sp,sp,-16
    80003544:	e406                	sd	ra,8(sp)
    80003546:	e022                	sd	s0,0(sp)
    80003548:	0800                	add	s0,sp,16
  initlock(&ftable.lock, "ftable");
    8000354a:	00003597          	auipc	a1,0x3
    8000354e:	d7658593          	add	a1,a1,-650 # 800062c0 <syscalls+0x310>
    80003552:	00011517          	auipc	a0,0x11
    80003556:	49e50513          	add	a0,a0,1182 # 800149f0 <ftable>
    8000355a:	aabfe0ef          	jal	80002004 <initlock>
}
    8000355e:	60a2                	ld	ra,8(sp)
    80003560:	6402                	ld	s0,0(sp)
    80003562:	0141                	add	sp,sp,16
    80003564:	8082                	ret

0000000080003566 <filealloc>:

// Allocate a file structure.
struct file*
filealloc(void)
{
    80003566:	1101                	add	sp,sp,-32
    80003568:	ec06                	sd	ra,24(sp)
    8000356a:	e822                	sd	s0,16(sp)
    8000356c:	e426                	sd	s1,8(sp)
    8000356e:	1000                	add	s0,sp,32
  struct file *f;

  acquire(&ftable.lock);
    80003570:	00011517          	auipc	a0,0x11
    80003574:	48050513          	add	a0,a0,1152 # 800149f0 <ftable>
    80003578:	aeffe0ef          	jal	80002066 <acquire>
  for(f = ftable.file; f < ftable.file + NFILE; f++){
    8000357c:	00011497          	auipc	s1,0x11
    80003580:	48c48493          	add	s1,s1,1164 # 80014a08 <ftable+0x18>
    80003584:	00012717          	auipc	a4,0x12
    80003588:	42470713          	add	a4,a4,1060 # 800159a8 <sb>
    if(f->ref == 0){
    8000358c:	40dc                	lw	a5,4(s1)
    8000358e:	cf89                	beqz	a5,800035a8 <filealloc+0x42>
  for(f = ftable.file; f < ftable.file + NFILE; f++){
    80003590:	02848493          	add	s1,s1,40
    80003594:	fee49ce3          	bne	s1,a4,8000358c <filealloc+0x26>
      f->ref = 1;
      release(&ftable.lock);
      return f;
    }
  }
  release(&ftable.lock);
    80003598:	00011517          	auipc	a0,0x11
    8000359c:	45850513          	add	a0,a0,1112 # 800149f0 <ftable>
    800035a0:	b6dfe0ef          	jal	8000210c <release>
  return 0;
    800035a4:	4481                	li	s1,0
    800035a6:	a809                	j	800035b8 <filealloc+0x52>
      f->ref = 1;
    800035a8:	4785                	li	a5,1
    800035aa:	c0dc                	sw	a5,4(s1)
      release(&ftable.lock);
    800035ac:	00011517          	auipc	a0,0x11
    800035b0:	44450513          	add	a0,a0,1092 # 800149f0 <ftable>
    800035b4:	b59fe0ef          	jal	8000210c <release>
}
    800035b8:	8526                	mv	a0,s1
    800035ba:	60e2                	ld	ra,24(sp)
    800035bc:	6442                	ld	s0,16(sp)
    800035be:	64a2                	ld	s1,8(sp)
    800035c0:	6105                	add	sp,sp,32
    800035c2:	8082                	ret

00000000800035c4 <filedup>:

// Increment ref count for file f.
struct file*
filedup(struct file *f)
{
    800035c4:	1101                	add	sp,sp,-32
    800035c6:	ec06                	sd	ra,24(sp)
    800035c8:	e822                	sd	s0,16(sp)
    800035ca:	e426                	sd	s1,8(sp)
    800035cc:	1000                	add	s0,sp,32
    800035ce:	84aa                	mv	s1,a0
  acquire(&ftable.lock);
    800035d0:	00011517          	auipc	a0,0x11
    800035d4:	42050513          	add	a0,a0,1056 # 800149f0 <ftable>
    800035d8:	a8ffe0ef          	jal	80002066 <acquire>
  if(f->ref < 1)
    800035dc:	40dc                	lw	a5,4(s1)
    800035de:	02f05163          	blez	a5,80003600 <filedup+0x3c>
    panic("filedup");
  f->ref++;
    800035e2:	40dc                	lw	a5,4(s1)
    800035e4:	2785                	addw	a5,a5,1
    800035e6:	c0dc                	sw	a5,4(s1)
  release(&ftable.lock);
    800035e8:	00011517          	auipc	a0,0x11
    800035ec:	40850513          	add	a0,a0,1032 # 800149f0 <ftable>
    800035f0:	b1dfe0ef          	jal	8000210c <release>
  return f;
}
    800035f4:	8526                	mv	a0,s1
    800035f6:	60e2                	ld	ra,24(sp)
    800035f8:	6442                	ld	s0,16(sp)
    800035fa:	64a2                	ld	s1,8(sp)
    800035fc:	6105                	add	sp,sp,32
    800035fe:	8082                	ret
    panic("filedup");
    80003600:	00003517          	auipc	a0,0x3
    80003604:	cc850513          	add	a0,a0,-824 # 800062c8 <syscalls+0x318>
    80003608:	b98fd0ef          	jal	800009a0 <panic>
    8000360c:	bfd9                	j	800035e2 <filedup+0x1e>

000000008000360e <fileclose>:

// Close file f.  (Decrement ref count, close when reaches 0.)
void
fileclose(struct file *f)
{
    8000360e:	7139                	add	sp,sp,-64
    80003610:	fc06                	sd	ra,56(sp)
    80003612:	f822                	sd	s0,48(sp)
    80003614:	f426                	sd	s1,40(sp)
    80003616:	f04a                	sd	s2,32(sp)
    80003618:	ec4e                	sd	s3,24(sp)
    8000361a:	e852                	sd	s4,16(sp)
    8000361c:	e456                	sd	s5,8(sp)
    8000361e:	0080                	add	s0,sp,64
    80003620:	84aa                	mv	s1,a0
  struct file ff;

  acquire(&ftable.lock);
    80003622:	00011517          	auipc	a0,0x11
    80003626:	3ce50513          	add	a0,a0,974 # 800149f0 <ftable>
    8000362a:	a3dfe0ef          	jal	80002066 <acquire>
  if(f->ref < 1)
    8000362e:	40dc                	lw	a5,4(s1)
    80003630:	04f05a63          	blez	a5,80003684 <fileclose+0x76>
    panic("fileclose");
  if(--f->ref > 0){
    80003634:	40dc                	lw	a5,4(s1)
    80003636:	37fd                	addw	a5,a5,-1
    80003638:	0007871b          	sext.w	a4,a5
    8000363c:	c0dc                	sw	a5,4(s1)
    8000363e:	04e04a63          	bgtz	a4,80003692 <fileclose+0x84>
    release(&ftable.lock);
    return;
  }
  ff = *f;
    80003642:	0004a903          	lw	s2,0(s1)
    80003646:	0094ca83          	lbu	s5,9(s1)
    8000364a:	0104ba03          	ld	s4,16(s1)
    8000364e:	0184b983          	ld	s3,24(s1)
  f->ref = 0;
    80003652:	0004a223          	sw	zero,4(s1)
  f->type = FD_NONE;
    80003656:	0004a023          	sw	zero,0(s1)
  release(&ftable.lock);
    8000365a:	00011517          	auipc	a0,0x11
    8000365e:	39650513          	add	a0,a0,918 # 800149f0 <ftable>
    80003662:	aabfe0ef          	jal	8000210c <release>

  if(ff.type == FD_PIPE){
    80003666:	4785                	li	a5,1
    80003668:	04f90463          	beq	s2,a5,800036b0 <fileclose+0xa2>
    pipeclose(ff.pipe, ff.writable);
  } else if(ff.type == FD_INODE || ff.type == FD_DEVICE){
    8000366c:	3979                	addw	s2,s2,-2
    8000366e:	4785                	li	a5,1
    80003670:	0327e763          	bltu	a5,s2,8000369e <fileclose+0x90>
    begin_op();
    80003674:	275010ef          	jal	800050e8 <begin_op>
    iput(ff.ip);
    80003678:	854e                	mv	a0,s3
    8000367a:	0ed000ef          	jal	80003f66 <iput>
    end_op();
    8000367e:	2d5010ef          	jal	80005152 <end_op>
    80003682:	a831                	j	8000369e <fileclose+0x90>
    panic("fileclose");
    80003684:	00003517          	auipc	a0,0x3
    80003688:	c4c50513          	add	a0,a0,-948 # 800062d0 <syscalls+0x320>
    8000368c:	b14fd0ef          	jal	800009a0 <panic>
    80003690:	b755                	j	80003634 <fileclose+0x26>
    release(&ftable.lock);
    80003692:	00011517          	auipc	a0,0x11
    80003696:	35e50513          	add	a0,a0,862 # 800149f0 <ftable>
    8000369a:	a73fe0ef          	jal	8000210c <release>
  }
}
    8000369e:	70e2                	ld	ra,56(sp)
    800036a0:	7442                	ld	s0,48(sp)
    800036a2:	74a2                	ld	s1,40(sp)
    800036a4:	7902                	ld	s2,32(sp)
    800036a6:	69e2                	ld	s3,24(sp)
    800036a8:	6a42                	ld	s4,16(sp)
    800036aa:	6aa2                	ld	s5,8(sp)
    800036ac:	6121                	add	sp,sp,64
    800036ae:	8082                	ret
    pipeclose(ff.pipe, ff.writable);
    800036b0:	85d6                	mv	a1,s5
    800036b2:	8552                	mv	a0,s4
    800036b4:	68e010ef          	jal	80004d42 <pipeclose>
    800036b8:	b7dd                	j	8000369e <fileclose+0x90>

00000000800036ba <filestat>:

// Get metadata about file f.
// addr is a user virtual address, pointing to a struct stat.
int
filestat(struct file *f, uint64 addr)
{
    800036ba:	715d                	add	sp,sp,-80
    800036bc:	e486                	sd	ra,72(sp)
    800036be:	e0a2                	sd	s0,64(sp)
    800036c0:	fc26                	sd	s1,56(sp)
    800036c2:	f84a                	sd	s2,48(sp)
    800036c4:	f44e                	sd	s3,40(sp)
    800036c6:	0880                	add	s0,sp,80
    800036c8:	84aa                	mv	s1,a0
    800036ca:	89ae                	mv	s3,a1
  struct proc *p = myproc();
    800036cc:	e97fe0ef          	jal	80002562 <myproc>
  struct stat st;
  
  if(f->type == FD_INODE || f->type == FD_DEVICE){
    800036d0:	409c                	lw	a5,0(s1)
    800036d2:	37f9                	addw	a5,a5,-2
    800036d4:	4705                	li	a4,1
    800036d6:	02f76f63          	bltu	a4,a5,80003714 <filestat+0x5a>
    800036da:	892a                	mv	s2,a0
    ilock(f->ip);
    800036dc:	6c88                	ld	a0,24(s1)
    800036de:	638000ef          	jal	80003d16 <ilock>
    stati(f->ip, &st);
    800036e2:	fb840593          	add	a1,s0,-72
    800036e6:	6c88                	ld	a0,24(s1)
    800036e8:	24b000ef          	jal	80004132 <stati>
    iunlock(f->ip);
    800036ec:	6c88                	ld	a0,24(s1)
    800036ee:	6d6000ef          	jal	80003dc4 <iunlock>
    if(copyout(p->pagetable, addr, (char *)&st, sizeof(st)) < 0)
    800036f2:	46e1                	li	a3,24
    800036f4:	fb840613          	add	a2,s0,-72
    800036f8:	85ce                	mv	a1,s3
    800036fa:	0c893503          	ld	a0,200(s2)
    800036fe:	cd8ff0ef          	jal	80002bd6 <copyout>
    80003702:	41f5551b          	sraw	a0,a0,0x1f
      return -1;
    return 0;
  }
  return -1;
}
    80003706:	60a6                	ld	ra,72(sp)
    80003708:	6406                	ld	s0,64(sp)
    8000370a:	74e2                	ld	s1,56(sp)
    8000370c:	7942                	ld	s2,48(sp)
    8000370e:	79a2                	ld	s3,40(sp)
    80003710:	6161                	add	sp,sp,80
    80003712:	8082                	ret
  return -1;
    80003714:	557d                	li	a0,-1
    80003716:	bfc5                	j	80003706 <filestat+0x4c>

0000000080003718 <fileread>:

// Read from file f.
// addr is a user virtual address.
int
fileread(struct file *f, uint64 addr, int n)
{
    80003718:	7179                	add	sp,sp,-48
    8000371a:	f406                	sd	ra,40(sp)
    8000371c:	f022                	sd	s0,32(sp)
    8000371e:	ec26                	sd	s1,24(sp)
    80003720:	e84a                	sd	s2,16(sp)
    80003722:	e44e                	sd	s3,8(sp)
    80003724:	1800                	add	s0,sp,48
  int r = 0;

  if(f->readable == 0)
    80003726:	00854783          	lbu	a5,8(a0)
    8000372a:	cbd1                	beqz	a5,800037be <fileread+0xa6>
    8000372c:	84aa                	mv	s1,a0
    8000372e:	892e                	mv	s2,a1
    80003730:	89b2                	mv	s3,a2
    return -1;

  if(f->type == FD_PIPE){
    80003732:	411c                	lw	a5,0(a0)
    80003734:	4705                	li	a4,1
    80003736:	02e78763          	beq	a5,a4,80003764 <fileread+0x4c>
    r = piperead(f->pipe, addr, n);
  } else if(f->type == FD_DEVICE){
    8000373a:	470d                	li	a4,3
    8000373c:	02e78963          	beq	a5,a4,8000376e <fileread+0x56>
    if(f->major < 0 || f->major >= NDEV || !devsw[f->major].read)
      return -1;
    r = devsw[f->major].read(1, addr, n);
  } else if(f->type == FD_INODE){
    80003740:	4709                	li	a4,2
    80003742:	04e78a63          	beq	a5,a4,80003796 <fileread+0x7e>
    ilock(f->ip);
    if((r = readi(f->ip, 1, addr, f->off, n)) > 0)
      f->off += r;
    iunlock(f->ip);
  } else {
    panic("fileread");
    80003746:	00003517          	auipc	a0,0x3
    8000374a:	b9a50513          	add	a0,a0,-1126 # 800062e0 <syscalls+0x330>
    8000374e:	a52fd0ef          	jal	800009a0 <panic>
  int r = 0;
    80003752:	4901                	li	s2,0
  }

  return r;
}
    80003754:	854a                	mv	a0,s2
    80003756:	70a2                	ld	ra,40(sp)
    80003758:	7402                	ld	s0,32(sp)
    8000375a:	64e2                	ld	s1,24(sp)
    8000375c:	6942                	ld	s2,16(sp)
    8000375e:	69a2                	ld	s3,8(sp)
    80003760:	6145                	add	sp,sp,48
    80003762:	8082                	ret
    r = piperead(f->pipe, addr, n);
    80003764:	6908                	ld	a0,16(a0)
    80003766:	708010ef          	jal	80004e6e <piperead>
    8000376a:	892a                	mv	s2,a0
    8000376c:	b7e5                	j	80003754 <fileread+0x3c>
    if(f->major < 0 || f->major >= NDEV || !devsw[f->major].read)
    8000376e:	02451783          	lh	a5,36(a0)
    80003772:	03079693          	sll	a3,a5,0x30
    80003776:	92c1                	srl	a3,a3,0x30
    80003778:	4725                	li	a4,9
    8000377a:	04d76463          	bltu	a4,a3,800037c2 <fileread+0xaa>
    8000377e:	0792                	sll	a5,a5,0x4
    80003780:	00011717          	auipc	a4,0x11
    80003784:	1d070713          	add	a4,a4,464 # 80014950 <devsw>
    80003788:	97ba                	add	a5,a5,a4
    8000378a:	639c                	ld	a5,0(a5)
    8000378c:	cf8d                	beqz	a5,800037c6 <fileread+0xae>
    r = devsw[f->major].read(1, addr, n);
    8000378e:	4505                	li	a0,1
    80003790:	9782                	jalr	a5
    80003792:	892a                	mv	s2,a0
    80003794:	b7c1                	j	80003754 <fileread+0x3c>
    ilock(f->ip);
    80003796:	6d08                	ld	a0,24(a0)
    80003798:	57e000ef          	jal	80003d16 <ilock>
    if((r = readi(f->ip, 1, addr, f->off, n)) > 0)
    8000379c:	874e                	mv	a4,s3
    8000379e:	5094                	lw	a3,32(s1)
    800037a0:	864a                	mv	a2,s2
    800037a2:	4585                	li	a1,1
    800037a4:	6c88                	ld	a0,24(s1)
    800037a6:	1b7000ef          	jal	8000415c <readi>
    800037aa:	892a                	mv	s2,a0
    800037ac:	00a05563          	blez	a0,800037b6 <fileread+0x9e>
      f->off += r;
    800037b0:	509c                	lw	a5,32(s1)
    800037b2:	9fa9                	addw	a5,a5,a0
    800037b4:	d09c                	sw	a5,32(s1)
    iunlock(f->ip);
    800037b6:	6c88                	ld	a0,24(s1)
    800037b8:	60c000ef          	jal	80003dc4 <iunlock>
    800037bc:	bf61                	j	80003754 <fileread+0x3c>
    return -1;
    800037be:	597d                	li	s2,-1
    800037c0:	bf51                	j	80003754 <fileread+0x3c>
      return -1;
    800037c2:	597d                	li	s2,-1
    800037c4:	bf41                	j	80003754 <fileread+0x3c>
    800037c6:	597d                	li	s2,-1
    800037c8:	b771                	j	80003754 <fileread+0x3c>

00000000800037ca <filewrite>:
int
filewrite(struct file *f, uint64 addr, int n)
{
  int r, ret = 0;

  if(f->writable == 0)
    800037ca:	00954783          	lbu	a5,9(a0)
    800037ce:	0e078c63          	beqz	a5,800038c6 <filewrite+0xfc>
{
    800037d2:	715d                	add	sp,sp,-80
    800037d4:	e486                	sd	ra,72(sp)
    800037d6:	e0a2                	sd	s0,64(sp)
    800037d8:	fc26                	sd	s1,56(sp)
    800037da:	f84a                	sd	s2,48(sp)
    800037dc:	f44e                	sd	s3,40(sp)
    800037de:	f052                	sd	s4,32(sp)
    800037e0:	ec56                	sd	s5,24(sp)
    800037e2:	e85a                	sd	s6,16(sp)
    800037e4:	e45e                	sd	s7,8(sp)
    800037e6:	e062                	sd	s8,0(sp)
    800037e8:	0880                	add	s0,sp,80
    800037ea:	84aa                	mv	s1,a0
    800037ec:	8aae                	mv	s5,a1
    800037ee:	8a32                	mv	s4,a2
    return -1;

  if(f->type == FD_PIPE){
    800037f0:	411c                	lw	a5,0(a0)
    800037f2:	4705                	li	a4,1
    800037f4:	02e78263          	beq	a5,a4,80003818 <filewrite+0x4e>
    ret = pipewrite(f->pipe, addr, n);
  } else if(f->type == FD_DEVICE){
    800037f8:	470d                	li	a4,3
    800037fa:	02e78363          	beq	a5,a4,80003820 <filewrite+0x56>
    if(f->major < 0 || f->major >= NDEV || !devsw[f->major].write)
      return -1;
    ret = devsw[f->major].write(1, addr, n);
  } else if(f->type == FD_INODE){
    800037fe:	4709                	li	a4,2
    80003800:	0ae79b63          	bne	a5,a4,800038b6 <filewrite+0xec>
    // the maximum log transaction size, including
    // i-node, indirect block, allocation blocks,
    // and 2 blocks of slop for non-aligned writes.
    int max = ((MAXOPBLOCKS-1-1-2) / 2) * BSIZE;
    int i = 0;
    while(i < n){
    80003804:	0ac05463          	blez	a2,800038ac <filewrite+0xe2>
    int i = 0;
    80003808:	4981                	li	s3,0
      int n1 = n - i;
      if(n1 > max)
    8000380a:	6b85                	lui	s7,0x1
    8000380c:	c00b8b93          	add	s7,s7,-1024 # c00 <_entry-0x7ffff400>
    80003810:	6c05                	lui	s8,0x1
    80003812:	c00c0c1b          	addw	s8,s8,-1024 # c00 <_entry-0x7ffff400>
    80003816:	a059                	j	8000389c <filewrite+0xd2>
    ret = pipewrite(f->pipe, addr, n);
    80003818:	6908                	ld	a0,16(a0)
    8000381a:	580010ef          	jal	80004d9a <pipewrite>
    8000381e:	a01d                	j	80003844 <filewrite+0x7a>
    if(f->major < 0 || f->major >= NDEV || !devsw[f->major].write)
    80003820:	02451783          	lh	a5,36(a0)
    80003824:	03079693          	sll	a3,a5,0x30
    80003828:	92c1                	srl	a3,a3,0x30
    8000382a:	4725                	li	a4,9
    8000382c:	08d76f63          	bltu	a4,a3,800038ca <filewrite+0x100>
    80003830:	0792                	sll	a5,a5,0x4
    80003832:	00011717          	auipc	a4,0x11
    80003836:	11e70713          	add	a4,a4,286 # 80014950 <devsw>
    8000383a:	97ba                	add	a5,a5,a4
    8000383c:	679c                	ld	a5,8(a5)
    8000383e:	cbc1                	beqz	a5,800038ce <filewrite+0x104>
    ret = devsw[f->major].write(1, addr, n);
    80003840:	4505                	li	a0,1
    80003842:	9782                	jalr	a5
  } else {
    panic("filewrite");
  }

  return ret;
}
    80003844:	60a6                	ld	ra,72(sp)
    80003846:	6406                	ld	s0,64(sp)
    80003848:	74e2                	ld	s1,56(sp)
    8000384a:	7942                	ld	s2,48(sp)
    8000384c:	79a2                	ld	s3,40(sp)
    8000384e:	7a02                	ld	s4,32(sp)
    80003850:	6ae2                	ld	s5,24(sp)
    80003852:	6b42                	ld	s6,16(sp)
    80003854:	6ba2                	ld	s7,8(sp)
    80003856:	6c02                	ld	s8,0(sp)
    80003858:	6161                	add	sp,sp,80
    8000385a:	8082                	ret
      if(n1 > max)
    8000385c:	00090b1b          	sext.w	s6,s2
      begin_op();
    80003860:	089010ef          	jal	800050e8 <begin_op>
      ilock(f->ip);
    80003864:	6c88                	ld	a0,24(s1)
    80003866:	4b0000ef          	jal	80003d16 <ilock>
      if ((r = writei(f->ip, 1, addr + i, f->off, n1)) > 0)
    8000386a:	875a                	mv	a4,s6
    8000386c:	5094                	lw	a3,32(s1)
    8000386e:	01598633          	add	a2,s3,s5
    80003872:	4585                	li	a1,1
    80003874:	6c88                	ld	a0,24(s1)
    80003876:	1cb000ef          	jal	80004240 <writei>
    8000387a:	892a                	mv	s2,a0
    8000387c:	00a05563          	blez	a0,80003886 <filewrite+0xbc>
        f->off += r;
    80003880:	509c                	lw	a5,32(s1)
    80003882:	9fa9                	addw	a5,a5,a0
    80003884:	d09c                	sw	a5,32(s1)
      iunlock(f->ip);
    80003886:	6c88                	ld	a0,24(s1)
    80003888:	53c000ef          	jal	80003dc4 <iunlock>
      end_op();
    8000388c:	0c7010ef          	jal	80005152 <end_op>
      if(r != n1){
    80003890:	012b1f63          	bne	s6,s2,800038ae <filewrite+0xe4>
      i += r;
    80003894:	013909bb          	addw	s3,s2,s3
    while(i < n){
    80003898:	0149db63          	bge	s3,s4,800038ae <filewrite+0xe4>
      int n1 = n - i;
    8000389c:	413a093b          	subw	s2,s4,s3
      if(n1 > max)
    800038a0:	0009079b          	sext.w	a5,s2
    800038a4:	fafbdce3          	bge	s7,a5,8000385c <filewrite+0x92>
    800038a8:	8962                	mv	s2,s8
    800038aa:	bf4d                	j	8000385c <filewrite+0x92>
    int i = 0;
    800038ac:	4981                	li	s3,0
    ret = (i == n ? n : -1);
    800038ae:	033a1263          	bne	s4,s3,800038d2 <filewrite+0x108>
    800038b2:	8552                	mv	a0,s4
    800038b4:	bf41                	j	80003844 <filewrite+0x7a>
    panic("filewrite");
    800038b6:	00003517          	auipc	a0,0x3
    800038ba:	a3a50513          	add	a0,a0,-1478 # 800062f0 <syscalls+0x340>
    800038be:	8e2fd0ef          	jal	800009a0 <panic>
  int r, ret = 0;
    800038c2:	4501                	li	a0,0
    800038c4:	b741                	j	80003844 <filewrite+0x7a>
    return -1;
    800038c6:	557d                	li	a0,-1
}
    800038c8:	8082                	ret
      return -1;
    800038ca:	557d                	li	a0,-1
    800038cc:	bfa5                	j	80003844 <filewrite+0x7a>
    800038ce:	557d                	li	a0,-1
    800038d0:	bf95                	j	80003844 <filewrite+0x7a>
    ret = (i == n ? n : -1);
    800038d2:	557d                	li	a0,-1
    800038d4:	bf85                	j	80003844 <filewrite+0x7a>

00000000800038d6 <iget>:
// Find the inode with number inum on device dev
// and return the in-memory copy. Does not lock
// the inode and does not read it from disk.
static struct inode*
iget(uint32 dev, uint32 inum)
{
    800038d6:	7179                	add	sp,sp,-48
    800038d8:	f406                	sd	ra,40(sp)
    800038da:	f022                	sd	s0,32(sp)
    800038dc:	ec26                	sd	s1,24(sp)
    800038de:	e84a                	sd	s2,16(sp)
    800038e0:	e44e                	sd	s3,8(sp)
    800038e2:	e052                	sd	s4,0(sp)
    800038e4:	1800                	add	s0,sp,48
    800038e6:	89aa                	mv	s3,a0
    800038e8:	8a2e                	mv	s4,a1
  struct inode *ip, *empty;

  acquire(&itable.lock);
    800038ea:	00012517          	auipc	a0,0x12
    800038ee:	0de50513          	add	a0,a0,222 # 800159c8 <itable>
    800038f2:	f74fe0ef          	jal	80002066 <acquire>

  // Is the inode already in the table?
  empty = 0;
    800038f6:	4901                	li	s2,0
  for(ip = &itable.inode[0]; ip < &itable.inode[NINODE]; ip++){
    800038f8:	00012497          	auipc	s1,0x12
    800038fc:	0e848493          	add	s1,s1,232 # 800159e0 <itable+0x18>
    80003900:	00014697          	auipc	a3,0x14
    80003904:	b7068693          	add	a3,a3,-1168 # 80017470 <disk>
    80003908:	a039                	j	80003916 <iget+0x40>
    if(ip->ref > 0 && ip->dev == dev && ip->inum == inum){
      ip->ref++;
      release(&itable.lock);
      return ip;
    }
    if(empty == 0 && ip->ref == 0)    // Remember empty slot.
    8000390a:	02090963          	beqz	s2,8000393c <iget+0x66>
  for(ip = &itable.inode[0]; ip < &itable.inode[NINODE]; ip++){
    8000390e:	08848493          	add	s1,s1,136
    80003912:	02d48863          	beq	s1,a3,80003942 <iget+0x6c>
    if(ip->ref > 0 && ip->dev == dev && ip->inum == inum){
    80003916:	449c                	lw	a5,8(s1)
    80003918:	fef059e3          	blez	a5,8000390a <iget+0x34>
    8000391c:	4098                	lw	a4,0(s1)
    8000391e:	ff3716e3          	bne	a4,s3,8000390a <iget+0x34>
    80003922:	40d8                	lw	a4,4(s1)
    80003924:	ff4713e3          	bne	a4,s4,8000390a <iget+0x34>
      ip->ref++;
    80003928:	2785                	addw	a5,a5,1
    8000392a:	c49c                	sw	a5,8(s1)
      release(&itable.lock);
    8000392c:	00012517          	auipc	a0,0x12
    80003930:	09c50513          	add	a0,a0,156 # 800159c8 <itable>
    80003934:	fd8fe0ef          	jal	8000210c <release>
      return ip;
    80003938:	8926                	mv	s2,s1
    8000393a:	a02d                	j	80003964 <iget+0x8e>
    if(empty == 0 && ip->ref == 0)    // Remember empty slot.
    8000393c:	fbe9                	bnez	a5,8000390e <iget+0x38>
    8000393e:	8926                	mv	s2,s1
    80003940:	b7f9                	j	8000390e <iget+0x38>
      empty = ip;
  }

  // Recycle an inode entry.
  if(empty == 0)
    80003942:	02090a63          	beqz	s2,80003976 <iget+0xa0>
    panic("iget: no inodes");

  ip = empty;
  ip->dev = dev;
    80003946:	01392023          	sw	s3,0(s2)
  ip->inum = inum;
    8000394a:	01492223          	sw	s4,4(s2)
  ip->ref = 1;
    8000394e:	4785                	li	a5,1
    80003950:	00f92423          	sw	a5,8(s2)
  ip->valid = 0;
    80003954:	04092023          	sw	zero,64(s2)
  release(&itable.lock);
    80003958:	00012517          	auipc	a0,0x12
    8000395c:	07050513          	add	a0,a0,112 # 800159c8 <itable>
    80003960:	facfe0ef          	jal	8000210c <release>

  return ip;
}
    80003964:	854a                	mv	a0,s2
    80003966:	70a2                	ld	ra,40(sp)
    80003968:	7402                	ld	s0,32(sp)
    8000396a:	64e2                	ld	s1,24(sp)
    8000396c:	6942                	ld	s2,16(sp)
    8000396e:	69a2                	ld	s3,8(sp)
    80003970:	6a02                	ld	s4,0(sp)
    80003972:	6145                	add	sp,sp,48
    80003974:	8082                	ret
    panic("iget: no inodes");
    80003976:	00003517          	auipc	a0,0x3
    8000397a:	98a50513          	add	a0,a0,-1654 # 80006300 <syscalls+0x350>
    8000397e:	822fd0ef          	jal	800009a0 <panic>
    80003982:	b7d1                	j	80003946 <iget+0x70>

0000000080003984 <readsb>:
{
    80003984:	1101                	add	sp,sp,-32
    80003986:	ec06                	sd	ra,24(sp)
    80003988:	e822                	sd	s0,16(sp)
    8000398a:	e426                	sd	s1,8(sp)
    8000398c:	e04a                	sd	s2,0(sp)
    8000398e:	1000                	add	s0,sp,32
    80003990:	892e                	mv	s2,a1
  bp = bread(dev, 1);
    80003992:	4585                	li	a1,1
    80003994:	a5dff0ef          	jal	800033f0 <bread>
    80003998:	84aa                	mv	s1,a0
  memmove(sb, bp->data, sizeof(*sb));
    8000399a:	02000613          	li	a2,32
    8000399e:	05850593          	add	a1,a0,88
    800039a2:	854a                	mv	a0,s2
    800039a4:	1f3010ef          	jal	80005396 <memmove>
  brelse(bp);
    800039a8:	8526                	mv	a0,s1
    800039aa:	aa7ff0ef          	jal	80003450 <brelse>
}
    800039ae:	60e2                	ld	ra,24(sp)
    800039b0:	6442                	ld	s0,16(sp)
    800039b2:	64a2                	ld	s1,8(sp)
    800039b4:	6902                	ld	s2,0(sp)
    800039b6:	6105                	add	sp,sp,32
    800039b8:	8082                	ret

00000000800039ba <bzero>:
{
    800039ba:	1101                	add	sp,sp,-32
    800039bc:	ec06                	sd	ra,24(sp)
    800039be:	e822                	sd	s0,16(sp)
    800039c0:	e426                	sd	s1,8(sp)
    800039c2:	1000                	add	s0,sp,32
  bp = bread(dev, bno);
    800039c4:	a2dff0ef          	jal	800033f0 <bread>
    800039c8:	84aa                	mv	s1,a0
  memset(bp->data, 0, BSIZE);
    800039ca:	40000613          	li	a2,1024
    800039ce:	4581                	li	a1,0
    800039d0:	05850513          	add	a0,a0,88
    800039d4:	167010ef          	jal	8000533a <memset>
  log_write(bp);
    800039d8:	8526                	mv	a0,s1
    800039da:	093010ef          	jal	8000526c <log_write>
  brelse(bp);
    800039de:	8526                	mv	a0,s1
    800039e0:	a71ff0ef          	jal	80003450 <brelse>
}
    800039e4:	60e2                	ld	ra,24(sp)
    800039e6:	6442                	ld	s0,16(sp)
    800039e8:	64a2                	ld	s1,8(sp)
    800039ea:	6105                	add	sp,sp,32
    800039ec:	8082                	ret

00000000800039ee <balloc>:
{
    800039ee:	711d                	add	sp,sp,-96
    800039f0:	ec86                	sd	ra,88(sp)
    800039f2:	e8a2                	sd	s0,80(sp)
    800039f4:	e4a6                	sd	s1,72(sp)
    800039f6:	e0ca                	sd	s2,64(sp)
    800039f8:	fc4e                	sd	s3,56(sp)
    800039fa:	f852                	sd	s4,48(sp)
    800039fc:	f456                	sd	s5,40(sp)
    800039fe:	f05a                	sd	s6,32(sp)
    80003a00:	ec5e                	sd	s7,24(sp)
    80003a02:	e862                	sd	s8,16(sp)
    80003a04:	e466                	sd	s9,8(sp)
    80003a06:	1080                	add	s0,sp,96
  for(b = 0; b < sb.size; b += BPB){
    80003a08:	00012797          	auipc	a5,0x12
    80003a0c:	fa47a783          	lw	a5,-92(a5) # 800159ac <sb+0x4>
    80003a10:	c3e1                	beqz	a5,80003ad0 <balloc+0xe2>
    80003a12:	8baa                	mv	s7,a0
    80003a14:	4a81                	li	s5,0
    bp = bread(dev, BBLOCK(b, sb));
    80003a16:	00012b17          	auipc	s6,0x12
    80003a1a:	f92b0b13          	add	s6,s6,-110 # 800159a8 <sb>
    for(bi = 0; bi < BPB && b + bi < sb.size; bi++){
    80003a1e:	4c01                	li	s8,0
      m = 1 << (bi % 8);
    80003a20:	4985                	li	s3,1
    for(bi = 0; bi < BPB && b + bi < sb.size; bi++){
    80003a22:	6a09                	lui	s4,0x2
  for(b = 0; b < sb.size; b += BPB){
    80003a24:	6c89                	lui	s9,0x2
    80003a26:	a881                	j	80003a76 <balloc+0x88>
        bp->data[bi/8] |= m;  // Mark block in use.
    80003a28:	97ca                	add	a5,a5,s2
    80003a2a:	8e55                	or	a2,a2,a3
    80003a2c:	04c78c23          	sb	a2,88(a5)
        log_write(bp);
    80003a30:	854a                	mv	a0,s2
    80003a32:	03b010ef          	jal	8000526c <log_write>
        brelse(bp);
    80003a36:	854a                	mv	a0,s2
    80003a38:	a19ff0ef          	jal	80003450 <brelse>
        bzero(dev, b + bi);
    80003a3c:	85a6                	mv	a1,s1
    80003a3e:	855e                	mv	a0,s7
    80003a40:	f7bff0ef          	jal	800039ba <bzero>
}
    80003a44:	8526                	mv	a0,s1
    80003a46:	60e6                	ld	ra,88(sp)
    80003a48:	6446                	ld	s0,80(sp)
    80003a4a:	64a6                	ld	s1,72(sp)
    80003a4c:	6906                	ld	s2,64(sp)
    80003a4e:	79e2                	ld	s3,56(sp)
    80003a50:	7a42                	ld	s4,48(sp)
    80003a52:	7aa2                	ld	s5,40(sp)
    80003a54:	7b02                	ld	s6,32(sp)
    80003a56:	6be2                	ld	s7,24(sp)
    80003a58:	6c42                	ld	s8,16(sp)
    80003a5a:	6ca2                	ld	s9,8(sp)
    80003a5c:	6125                	add	sp,sp,96
    80003a5e:	8082                	ret
    brelse(bp);
    80003a60:	854a                	mv	a0,s2
    80003a62:	9efff0ef          	jal	80003450 <brelse>
  for(b = 0; b < sb.size; b += BPB){
    80003a66:	015c87bb          	addw	a5,s9,s5
    80003a6a:	00078a9b          	sext.w	s5,a5
    80003a6e:	004b2703          	lw	a4,4(s6)
    80003a72:	04eaff63          	bgeu	s5,a4,80003ad0 <balloc+0xe2>
    bp = bread(dev, BBLOCK(b, sb));
    80003a76:	41fad79b          	sraw	a5,s5,0x1f
    80003a7a:	0137d79b          	srlw	a5,a5,0x13
    80003a7e:	015787bb          	addw	a5,a5,s5
    80003a82:	40d7d79b          	sraw	a5,a5,0xd
    80003a86:	01cb2583          	lw	a1,28(s6)
    80003a8a:	9dbd                	addw	a1,a1,a5
    80003a8c:	855e                	mv	a0,s7
    80003a8e:	963ff0ef          	jal	800033f0 <bread>
    80003a92:	892a                	mv	s2,a0
    for(bi = 0; bi < BPB && b + bi < sb.size; bi++){
    80003a94:	004b2503          	lw	a0,4(s6)
    80003a98:	000a849b          	sext.w	s1,s5
    80003a9c:	8762                	mv	a4,s8
    80003a9e:	fca4f1e3          	bgeu	s1,a0,80003a60 <balloc+0x72>
      m = 1 << (bi % 8);
    80003aa2:	00777693          	and	a3,a4,7
    80003aa6:	00d996bb          	sllw	a3,s3,a3
      if((bp->data[bi/8] & m) == 0){  // Is block free?
    80003aaa:	41f7579b          	sraw	a5,a4,0x1f
    80003aae:	01d7d79b          	srlw	a5,a5,0x1d
    80003ab2:	9fb9                	addw	a5,a5,a4
    80003ab4:	4037d79b          	sraw	a5,a5,0x3
    80003ab8:	00f90633          	add	a2,s2,a5
    80003abc:	05864603          	lbu	a2,88(a2) # 2058 <_entry-0x7fffdfa8>
    80003ac0:	00c6f5b3          	and	a1,a3,a2
    80003ac4:	d1b5                	beqz	a1,80003a28 <balloc+0x3a>
    for(bi = 0; bi < BPB && b + bi < sb.size; bi++){
    80003ac6:	2705                	addw	a4,a4,1
    80003ac8:	2485                	addw	s1,s1,1
    80003aca:	fd471ae3          	bne	a4,s4,80003a9e <balloc+0xb0>
    80003ace:	bf49                	j	80003a60 <balloc+0x72>
  printf("balloc: out of blocks\n");
    80003ad0:	00003517          	auipc	a0,0x3
    80003ad4:	84050513          	add	a0,a0,-1984 # 80006310 <syscalls+0x360>
    80003ad8:	8affc0ef          	jal	80000386 <printf>
  return 0;
    80003adc:	4481                	li	s1,0
    80003ade:	b79d                	j	80003a44 <balloc+0x56>

0000000080003ae0 <bfree>:
{
    80003ae0:	7179                	add	sp,sp,-48
    80003ae2:	f406                	sd	ra,40(sp)
    80003ae4:	f022                	sd	s0,32(sp)
    80003ae6:	ec26                	sd	s1,24(sp)
    80003ae8:	e84a                	sd	s2,16(sp)
    80003aea:	e44e                	sd	s3,8(sp)
    80003aec:	1800                	add	s0,sp,48
    80003aee:	84ae                	mv	s1,a1
  bp = bread(dev, BBLOCK(b, sb));
    80003af0:	00d5d59b          	srlw	a1,a1,0xd
    80003af4:	00012797          	auipc	a5,0x12
    80003af8:	ed07a783          	lw	a5,-304(a5) # 800159c4 <sb+0x1c>
    80003afc:	9dbd                	addw	a1,a1,a5
    80003afe:	8f3ff0ef          	jal	800033f0 <bread>
    80003b02:	892a                	mv	s2,a0
  m = 1 << (bi % 8);
    80003b04:	0074f793          	and	a5,s1,7
    80003b08:	4985                	li	s3,1
    80003b0a:	00f999bb          	sllw	s3,s3,a5
  if((bp->data[bi/8] & m) == 0)
    80003b0e:	14ce                	sll	s1,s1,0x33
    80003b10:	90d9                	srl	s1,s1,0x36
    80003b12:	009507b3          	add	a5,a0,s1
    80003b16:	0587c783          	lbu	a5,88(a5)
    80003b1a:	00f9f7b3          	and	a5,s3,a5
    80003b1e:	c79d                	beqz	a5,80003b4c <bfree+0x6c>
  bp->data[bi/8] &= ~m;
    80003b20:	94ca                	add	s1,s1,s2
    80003b22:	fff9c993          	not	s3,s3
    80003b26:	0584c783          	lbu	a5,88(s1)
    80003b2a:	0137f7b3          	and	a5,a5,s3
    80003b2e:	04f48c23          	sb	a5,88(s1)
  log_write(bp);
    80003b32:	854a                	mv	a0,s2
    80003b34:	738010ef          	jal	8000526c <log_write>
  brelse(bp);
    80003b38:	854a                	mv	a0,s2
    80003b3a:	917ff0ef          	jal	80003450 <brelse>
}
    80003b3e:	70a2                	ld	ra,40(sp)
    80003b40:	7402                	ld	s0,32(sp)
    80003b42:	64e2                	ld	s1,24(sp)
    80003b44:	6942                	ld	s2,16(sp)
    80003b46:	69a2                	ld	s3,8(sp)
    80003b48:	6145                	add	sp,sp,48
    80003b4a:	8082                	ret
    panic("freeing free block");
    80003b4c:	00002517          	auipc	a0,0x2
    80003b50:	7dc50513          	add	a0,a0,2012 # 80006328 <syscalls+0x378>
    80003b54:	e4dfc0ef          	jal	800009a0 <panic>
    80003b58:	b7e1                	j	80003b20 <bfree+0x40>

0000000080003b5a <iinit>:
{
    80003b5a:	7179                	add	sp,sp,-48
    80003b5c:	f406                	sd	ra,40(sp)
    80003b5e:	f022                	sd	s0,32(sp)
    80003b60:	ec26                	sd	s1,24(sp)
    80003b62:	e84a                	sd	s2,16(sp)
    80003b64:	e44e                	sd	s3,8(sp)
    80003b66:	1800                	add	s0,sp,48
  initlock(&itable.lock, "itable");
    80003b68:	00002597          	auipc	a1,0x2
    80003b6c:	7d858593          	add	a1,a1,2008 # 80006340 <syscalls+0x390>
    80003b70:	00012517          	auipc	a0,0x12
    80003b74:	e5850513          	add	a0,a0,-424 # 800159c8 <itable>
    80003b78:	c8cfe0ef          	jal	80002004 <initlock>
  for(i = 0; i < NINODE; i++) {
    80003b7c:	00012497          	auipc	s1,0x12
    80003b80:	e7448493          	add	s1,s1,-396 # 800159f0 <itable+0x28>
    80003b84:	00014997          	auipc	s3,0x14
    80003b88:	8fc98993          	add	s3,s3,-1796 # 80017480 <disk+0x10>
    initsleeplock(&itable.inode[i].lock, "inode");
    80003b8c:	00002917          	auipc	s2,0x2
    80003b90:	7bc90913          	add	s2,s2,1980 # 80006348 <syscalls+0x398>
    80003b94:	85ca                	mv	a1,s2
    80003b96:	8526                	mv	a0,s1
    80003b98:	29d000ef          	jal	80004634 <initsleeplock>
  for(i = 0; i < NINODE; i++) {
    80003b9c:	08848493          	add	s1,s1,136
    80003ba0:	ff349ae3          	bne	s1,s3,80003b94 <iinit+0x3a>
}
    80003ba4:	70a2                	ld	ra,40(sp)
    80003ba6:	7402                	ld	s0,32(sp)
    80003ba8:	64e2                	ld	s1,24(sp)
    80003baa:	6942                	ld	s2,16(sp)
    80003bac:	69a2                	ld	s3,8(sp)
    80003bae:	6145                	add	sp,sp,48
    80003bb0:	8082                	ret

0000000080003bb2 <ialloc>:
{
    80003bb2:	7139                	add	sp,sp,-64
    80003bb4:	fc06                	sd	ra,56(sp)
    80003bb6:	f822                	sd	s0,48(sp)
    80003bb8:	f426                	sd	s1,40(sp)
    80003bba:	f04a                	sd	s2,32(sp)
    80003bbc:	ec4e                	sd	s3,24(sp)
    80003bbe:	e852                	sd	s4,16(sp)
    80003bc0:	e456                	sd	s5,8(sp)
    80003bc2:	e05a                	sd	s6,0(sp)
    80003bc4:	0080                	add	s0,sp,64
  for(inum = 1; inum < sb.ninodes; inum++){
    80003bc6:	00012717          	auipc	a4,0x12
    80003bca:	dee72703          	lw	a4,-530(a4) # 800159b4 <sb+0xc>
    80003bce:	4785                	li	a5,1
    80003bd0:	04e7f463          	bgeu	a5,a4,80003c18 <ialloc+0x66>
    80003bd4:	8aaa                	mv	s5,a0
    80003bd6:	8b2e                	mv	s6,a1
    80003bd8:	4905                	li	s2,1
    bp = bread(dev, IBLOCK(inum, sb));
    80003bda:	00012a17          	auipc	s4,0x12
    80003bde:	dcea0a13          	add	s4,s4,-562 # 800159a8 <sb>
    80003be2:	00495593          	srl	a1,s2,0x4
    80003be6:	018a2783          	lw	a5,24(s4)
    80003bea:	9dbd                	addw	a1,a1,a5
    80003bec:	8556                	mv	a0,s5
    80003bee:	803ff0ef          	jal	800033f0 <bread>
    80003bf2:	84aa                	mv	s1,a0
    dip = (struct dinode*)bp->data + inum%IPB;
    80003bf4:	05850993          	add	s3,a0,88
    80003bf8:	00f97793          	and	a5,s2,15
    80003bfc:	079a                	sll	a5,a5,0x6
    80003bfe:	99be                	add	s3,s3,a5
    if(dip->type == 0){  // a free inode
    80003c00:	00099783          	lh	a5,0(s3)
    80003c04:	cb9d                	beqz	a5,80003c3a <ialloc+0x88>
    brelse(bp);
    80003c06:	84bff0ef          	jal	80003450 <brelse>
  for(inum = 1; inum < sb.ninodes; inum++){
    80003c0a:	0905                	add	s2,s2,1
    80003c0c:	00ca2703          	lw	a4,12(s4)
    80003c10:	0009079b          	sext.w	a5,s2
    80003c14:	fce7e7e3          	bltu	a5,a4,80003be2 <ialloc+0x30>
  printf("ialloc: no inodes\n");
    80003c18:	00002517          	auipc	a0,0x2
    80003c1c:	73850513          	add	a0,a0,1848 # 80006350 <syscalls+0x3a0>
    80003c20:	f66fc0ef          	jal	80000386 <printf>
  return 0;
    80003c24:	4501                	li	a0,0
}
    80003c26:	70e2                	ld	ra,56(sp)
    80003c28:	7442                	ld	s0,48(sp)
    80003c2a:	74a2                	ld	s1,40(sp)
    80003c2c:	7902                	ld	s2,32(sp)
    80003c2e:	69e2                	ld	s3,24(sp)
    80003c30:	6a42                	ld	s4,16(sp)
    80003c32:	6aa2                	ld	s5,8(sp)
    80003c34:	6b02                	ld	s6,0(sp)
    80003c36:	6121                	add	sp,sp,64
    80003c38:	8082                	ret
      memset(dip, 0, sizeof(*dip));
    80003c3a:	04000613          	li	a2,64
    80003c3e:	4581                	li	a1,0
    80003c40:	854e                	mv	a0,s3
    80003c42:	6f8010ef          	jal	8000533a <memset>
      dip->type = type;
    80003c46:	01699023          	sh	s6,0(s3)
      log_write(bp);   // mark it allocated on the disk
    80003c4a:	8526                	mv	a0,s1
    80003c4c:	620010ef          	jal	8000526c <log_write>
      brelse(bp);
    80003c50:	8526                	mv	a0,s1
    80003c52:	ffeff0ef          	jal	80003450 <brelse>
      return iget(dev, inum);
    80003c56:	0009059b          	sext.w	a1,s2
    80003c5a:	8556                	mv	a0,s5
    80003c5c:	c7bff0ef          	jal	800038d6 <iget>
    80003c60:	b7d9                	j	80003c26 <ialloc+0x74>

0000000080003c62 <iupdate>:
{
    80003c62:	1101                	add	sp,sp,-32
    80003c64:	ec06                	sd	ra,24(sp)
    80003c66:	e822                	sd	s0,16(sp)
    80003c68:	e426                	sd	s1,8(sp)
    80003c6a:	e04a                	sd	s2,0(sp)
    80003c6c:	1000                	add	s0,sp,32
    80003c6e:	84aa                	mv	s1,a0
  bp = bread(ip->dev, IBLOCK(ip->inum, sb));
    80003c70:	415c                	lw	a5,4(a0)
    80003c72:	0047d79b          	srlw	a5,a5,0x4
    80003c76:	00012597          	auipc	a1,0x12
    80003c7a:	d4a5a583          	lw	a1,-694(a1) # 800159c0 <sb+0x18>
    80003c7e:	9dbd                	addw	a1,a1,a5
    80003c80:	4108                	lw	a0,0(a0)
    80003c82:	f6eff0ef          	jal	800033f0 <bread>
    80003c86:	892a                	mv	s2,a0
  dip = (struct dinode*)bp->data + ip->inum%IPB;
    80003c88:	05850793          	add	a5,a0,88
    80003c8c:	40d8                	lw	a4,4(s1)
    80003c8e:	8b3d                	and	a4,a4,15
    80003c90:	071a                	sll	a4,a4,0x6
    80003c92:	97ba                	add	a5,a5,a4
  dip->type = ip->type;
    80003c94:	04449703          	lh	a4,68(s1)
    80003c98:	00e79023          	sh	a4,0(a5)
  dip->major = ip->major;
    80003c9c:	04649703          	lh	a4,70(s1)
    80003ca0:	00e79123          	sh	a4,2(a5)
  dip->minor = ip->minor;
    80003ca4:	04849703          	lh	a4,72(s1)
    80003ca8:	00e79223          	sh	a4,4(a5)
  dip->nlink = ip->nlink;
    80003cac:	04a49703          	lh	a4,74(s1)
    80003cb0:	00e79323          	sh	a4,6(a5)
  dip->size = ip->size;
    80003cb4:	44f8                	lw	a4,76(s1)
    80003cb6:	c798                	sw	a4,8(a5)
  memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
    80003cb8:	03400613          	li	a2,52
    80003cbc:	05048593          	add	a1,s1,80
    80003cc0:	00c78513          	add	a0,a5,12
    80003cc4:	6d2010ef          	jal	80005396 <memmove>
  log_write(bp);
    80003cc8:	854a                	mv	a0,s2
    80003cca:	5a2010ef          	jal	8000526c <log_write>
  brelse(bp);
    80003cce:	854a                	mv	a0,s2
    80003cd0:	f80ff0ef          	jal	80003450 <brelse>
}
    80003cd4:	60e2                	ld	ra,24(sp)
    80003cd6:	6442                	ld	s0,16(sp)
    80003cd8:	64a2                	ld	s1,8(sp)
    80003cda:	6902                	ld	s2,0(sp)
    80003cdc:	6105                	add	sp,sp,32
    80003cde:	8082                	ret

0000000080003ce0 <idup>:

// Increment reference count for ip.
// Returns ip to enable ip = idup(ip1) idiom.
struct inode*
idup(struct inode *ip)
{
    80003ce0:	1101                	add	sp,sp,-32
    80003ce2:	ec06                	sd	ra,24(sp)
    80003ce4:	e822                	sd	s0,16(sp)
    80003ce6:	e426                	sd	s1,8(sp)
    80003ce8:	1000                	add	s0,sp,32
    80003cea:	84aa                	mv	s1,a0
  acquire(&itable.lock);
    80003cec:	00012517          	auipc	a0,0x12
    80003cf0:	cdc50513          	add	a0,a0,-804 # 800159c8 <itable>
    80003cf4:	b72fe0ef          	jal	80002066 <acquire>
  ip->ref++;
    80003cf8:	449c                	lw	a5,8(s1)
    80003cfa:	2785                	addw	a5,a5,1
    80003cfc:	c49c                	sw	a5,8(s1)
  release(&itable.lock);
    80003cfe:	00012517          	auipc	a0,0x12
    80003d02:	cca50513          	add	a0,a0,-822 # 800159c8 <itable>
    80003d06:	c06fe0ef          	jal	8000210c <release>
  return ip;
}
    80003d0a:	8526                	mv	a0,s1
    80003d0c:	60e2                	ld	ra,24(sp)
    80003d0e:	6442                	ld	s0,16(sp)
    80003d10:	64a2                	ld	s1,8(sp)
    80003d12:	6105                	add	sp,sp,32
    80003d14:	8082                	ret

0000000080003d16 <ilock>:

// Lock the given inode.
// Reads the inode from disk if necessary.
void
ilock(struct inode *ip)
{
    80003d16:	1101                	add	sp,sp,-32
    80003d18:	ec06                	sd	ra,24(sp)
    80003d1a:	e822                	sd	s0,16(sp)
    80003d1c:	e426                	sd	s1,8(sp)
    80003d1e:	e04a                	sd	s2,0(sp)
    80003d20:	1000                	add	s0,sp,32
    80003d22:	84aa                	mv	s1,a0
  struct buf *bp;
  struct dinode *dip;

  if(ip == 0 || ip->ref < 1)
    80003d24:	c501                	beqz	a0,80003d2c <ilock+0x16>
    80003d26:	451c                	lw	a5,8(a0)
    80003d28:	00f04863          	bgtz	a5,80003d38 <ilock+0x22>
    panic("ilock");
    80003d2c:	00002517          	auipc	a0,0x2
    80003d30:	63c50513          	add	a0,a0,1596 # 80006368 <syscalls+0x3b8>
    80003d34:	c6dfc0ef          	jal	800009a0 <panic>

  acquiresleep(&ip->lock);
    80003d38:	01048513          	add	a0,s1,16
    80003d3c:	12f000ef          	jal	8000466a <acquiresleep>

  if(ip->valid == 0){
    80003d40:	40bc                	lw	a5,64(s1)
    80003d42:	c799                	beqz	a5,80003d50 <ilock+0x3a>
    brelse(bp);
    ip->valid = 1;
    if(ip->type == 0)
      panic("ilock: no type");
  }
}
    80003d44:	60e2                	ld	ra,24(sp)
    80003d46:	6442                	ld	s0,16(sp)
    80003d48:	64a2                	ld	s1,8(sp)
    80003d4a:	6902                	ld	s2,0(sp)
    80003d4c:	6105                	add	sp,sp,32
    80003d4e:	8082                	ret
    bp = bread(ip->dev, IBLOCK(ip->inum, sb));
    80003d50:	40dc                	lw	a5,4(s1)
    80003d52:	0047d79b          	srlw	a5,a5,0x4
    80003d56:	00012597          	auipc	a1,0x12
    80003d5a:	c6a5a583          	lw	a1,-918(a1) # 800159c0 <sb+0x18>
    80003d5e:	9dbd                	addw	a1,a1,a5
    80003d60:	4088                	lw	a0,0(s1)
    80003d62:	e8eff0ef          	jal	800033f0 <bread>
    80003d66:	892a                	mv	s2,a0
    dip = (struct dinode*)bp->data + ip->inum%IPB;
    80003d68:	05850593          	add	a1,a0,88
    80003d6c:	40dc                	lw	a5,4(s1)
    80003d6e:	8bbd                	and	a5,a5,15
    80003d70:	079a                	sll	a5,a5,0x6
    80003d72:	95be                	add	a1,a1,a5
    ip->type = dip->type;
    80003d74:	00059783          	lh	a5,0(a1)
    80003d78:	04f49223          	sh	a5,68(s1)
    ip->major = dip->major;
    80003d7c:	00259783          	lh	a5,2(a1)
    80003d80:	04f49323          	sh	a5,70(s1)
    ip->minor = dip->minor;
    80003d84:	00459783          	lh	a5,4(a1)
    80003d88:	04f49423          	sh	a5,72(s1)
    ip->nlink = dip->nlink;
    80003d8c:	00659783          	lh	a5,6(a1)
    80003d90:	04f49523          	sh	a5,74(s1)
    ip->size = dip->size;
    80003d94:	459c                	lw	a5,8(a1)
    80003d96:	c4fc                	sw	a5,76(s1)
    memmove(ip->addrs, dip->addrs, sizeof(ip->addrs));
    80003d98:	03400613          	li	a2,52
    80003d9c:	05b1                	add	a1,a1,12
    80003d9e:	05048513          	add	a0,s1,80
    80003da2:	5f4010ef          	jal	80005396 <memmove>
    brelse(bp);
    80003da6:	854a                	mv	a0,s2
    80003da8:	ea8ff0ef          	jal	80003450 <brelse>
    ip->valid = 1;
    80003dac:	4785                	li	a5,1
    80003dae:	c0bc                	sw	a5,64(s1)
    if(ip->type == 0)
    80003db0:	04449783          	lh	a5,68(s1)
    80003db4:	fbc1                	bnez	a5,80003d44 <ilock+0x2e>
      panic("ilock: no type");
    80003db6:	00002517          	auipc	a0,0x2
    80003dba:	5ba50513          	add	a0,a0,1466 # 80006370 <syscalls+0x3c0>
    80003dbe:	be3fc0ef          	jal	800009a0 <panic>
}
    80003dc2:	b749                	j	80003d44 <ilock+0x2e>

0000000080003dc4 <iunlock>:

// Unlock the given inode.
void
iunlock(struct inode *ip)
{
    80003dc4:	1101                	add	sp,sp,-32
    80003dc6:	ec06                	sd	ra,24(sp)
    80003dc8:	e822                	sd	s0,16(sp)
    80003dca:	e426                	sd	s1,8(sp)
    80003dcc:	1000                	add	s0,sp,32
    80003dce:	84aa                	mv	s1,a0
  if(ip == 0 || !holdingsleep(&ip->lock) || ip->ref < 1)
    80003dd0:	c901                	beqz	a0,80003de0 <iunlock+0x1c>
    80003dd2:	0541                	add	a0,a0,16
    80003dd4:	115000ef          	jal	800046e8 <holdingsleep>
    80003dd8:	c501                	beqz	a0,80003de0 <iunlock+0x1c>
    80003dda:	449c                	lw	a5,8(s1)
    80003ddc:	00f04863          	bgtz	a5,80003dec <iunlock+0x28>
    panic("iunlock");
    80003de0:	00002517          	auipc	a0,0x2
    80003de4:	5a050513          	add	a0,a0,1440 # 80006380 <syscalls+0x3d0>
    80003de8:	bb9fc0ef          	jal	800009a0 <panic>

  releasesleep(&ip->lock);
    80003dec:	01048513          	add	a0,s1,16
    80003df0:	0c1000ef          	jal	800046b0 <releasesleep>
}
    80003df4:	60e2                	ld	ra,24(sp)
    80003df6:	6442                	ld	s0,16(sp)
    80003df8:	64a2                	ld	s1,8(sp)
    80003dfa:	6105                	add	sp,sp,32
    80003dfc:	8082                	ret

0000000080003dfe <bmap>:
// Return the disk block address of the nth block in inode ip.
// If there is no such block, bmap allocates one.
// returns 0 if out of disk space.
 uint32
bmap(struct inode *ip, uint32 bn)
{
    80003dfe:	7179                	add	sp,sp,-48
    80003e00:	f406                	sd	ra,40(sp)
    80003e02:	f022                	sd	s0,32(sp)
    80003e04:	ec26                	sd	s1,24(sp)
    80003e06:	e84a                	sd	s2,16(sp)
    80003e08:	e44e                	sd	s3,8(sp)
    80003e0a:	e052                	sd	s4,0(sp)
    80003e0c:	1800                	add	s0,sp,48
    80003e0e:	89aa                	mv	s3,a0
  uint32 addr, *a;
  struct buf *bp;

  if(bn < NDIRECT){
    80003e10:	47ad                	li	a5,11
    80003e12:	02b7ef63          	bltu	a5,a1,80003e50 <bmap+0x52>
    if((addr = ip->addrs[bn]) == 0){
    80003e16:	02059793          	sll	a5,a1,0x20
    80003e1a:	01e7d593          	srl	a1,a5,0x1e
    80003e1e:	00b504b3          	add	s1,a0,a1
    80003e22:	0504a903          	lw	s2,80(s1)
    80003e26:	00090b63          	beqz	s2,80003e3c <bmap+0x3e>
    return addr;
  }

  panic("bmap: out of range");
  return 0;
}
    80003e2a:	854a                	mv	a0,s2
    80003e2c:	70a2                	ld	ra,40(sp)
    80003e2e:	7402                	ld	s0,32(sp)
    80003e30:	64e2                	ld	s1,24(sp)
    80003e32:	6942                	ld	s2,16(sp)
    80003e34:	69a2                	ld	s3,8(sp)
    80003e36:	6a02                	ld	s4,0(sp)
    80003e38:	6145                	add	sp,sp,48
    80003e3a:	8082                	ret
      addr = balloc(ip->dev);
    80003e3c:	4108                	lw	a0,0(a0)
    80003e3e:	bb1ff0ef          	jal	800039ee <balloc>
    80003e42:	0005091b          	sext.w	s2,a0
      if(addr == 0)
    80003e46:	fe0902e3          	beqz	s2,80003e2a <bmap+0x2c>
      ip->addrs[bn] = addr;
    80003e4a:	0524a823          	sw	s2,80(s1)
    80003e4e:	bff1                	j	80003e2a <bmap+0x2c>
  bn -= NDIRECT;
    80003e50:	ff45849b          	addw	s1,a1,-12
    80003e54:	0004871b          	sext.w	a4,s1
  if(bn < NINDIRECT){
    80003e58:	0ff00793          	li	a5,255
    80003e5c:	06e7e363          	bltu	a5,a4,80003ec2 <bmap+0xc4>
    if((addr = ip->addrs[NDIRECT]) == 0){
    80003e60:	08052903          	lw	s2,128(a0)
    80003e64:	00091b63          	bnez	s2,80003e7a <bmap+0x7c>
      addr = balloc(ip->dev);
    80003e68:	4108                	lw	a0,0(a0)
    80003e6a:	b85ff0ef          	jal	800039ee <balloc>
    80003e6e:	0005091b          	sext.w	s2,a0
      if(addr == 0)
    80003e72:	fa090ce3          	beqz	s2,80003e2a <bmap+0x2c>
      ip->addrs[NDIRECT] = addr;
    80003e76:	0929a023          	sw	s2,128(s3)
    bp = bread(ip->dev, addr);
    80003e7a:	85ca                	mv	a1,s2
    80003e7c:	0009a503          	lw	a0,0(s3)
    80003e80:	d70ff0ef          	jal	800033f0 <bread>
    80003e84:	8a2a                	mv	s4,a0
    a = (uint32*)bp->data;
    80003e86:	05850793          	add	a5,a0,88
    if((addr = a[bn]) == 0){
    80003e8a:	02049713          	sll	a4,s1,0x20
    80003e8e:	01e75593          	srl	a1,a4,0x1e
    80003e92:	00b784b3          	add	s1,a5,a1
    80003e96:	0004a903          	lw	s2,0(s1)
    80003e9a:	00090663          	beqz	s2,80003ea6 <bmap+0xa8>
    brelse(bp);
    80003e9e:	8552                	mv	a0,s4
    80003ea0:	db0ff0ef          	jal	80003450 <brelse>
    return addr;
    80003ea4:	b759                	j	80003e2a <bmap+0x2c>
      addr = balloc(ip->dev);
    80003ea6:	0009a503          	lw	a0,0(s3)
    80003eaa:	b45ff0ef          	jal	800039ee <balloc>
    80003eae:	0005091b          	sext.w	s2,a0
      if(addr){
    80003eb2:	fe0906e3          	beqz	s2,80003e9e <bmap+0xa0>
        a[bn] = addr;
    80003eb6:	0124a023          	sw	s2,0(s1)
        log_write(bp);
    80003eba:	8552                	mv	a0,s4
    80003ebc:	3b0010ef          	jal	8000526c <log_write>
    80003ec0:	bff9                	j	80003e9e <bmap+0xa0>
  panic("bmap: out of range");
    80003ec2:	00002517          	auipc	a0,0x2
    80003ec6:	4c650513          	add	a0,a0,1222 # 80006388 <syscalls+0x3d8>
    80003eca:	ad7fc0ef          	jal	800009a0 <panic>
  return 0;
    80003ece:	4901                	li	s2,0
    80003ed0:	bfa9                	j	80003e2a <bmap+0x2c>

0000000080003ed2 <itrunc>:

// Truncate inode (discard contents).
// Caller must hold ip->lock.
void
itrunc(struct inode *ip)
{
    80003ed2:	7179                	add	sp,sp,-48
    80003ed4:	f406                	sd	ra,40(sp)
    80003ed6:	f022                	sd	s0,32(sp)
    80003ed8:	ec26                	sd	s1,24(sp)
    80003eda:	e84a                	sd	s2,16(sp)
    80003edc:	e44e                	sd	s3,8(sp)
    80003ede:	e052                	sd	s4,0(sp)
    80003ee0:	1800                	add	s0,sp,48
    80003ee2:	89aa                	mv	s3,a0
  int i, j;
  struct buf *bp;
  uint32*a;

  for(i = 0; i < NDIRECT; i++){
    80003ee4:	05050493          	add	s1,a0,80
    80003ee8:	08050913          	add	s2,a0,128
    80003eec:	a021                	j	80003ef4 <itrunc+0x22>
    80003eee:	0491                	add	s1,s1,4
    80003ef0:	01248b63          	beq	s1,s2,80003f06 <itrunc+0x34>
    if(ip->addrs[i]){
    80003ef4:	408c                	lw	a1,0(s1)
    80003ef6:	dde5                	beqz	a1,80003eee <itrunc+0x1c>
      bfree(ip->dev, ip->addrs[i]);
    80003ef8:	0009a503          	lw	a0,0(s3)
    80003efc:	be5ff0ef          	jal	80003ae0 <bfree>
      ip->addrs[i] = 0;
    80003f00:	0004a023          	sw	zero,0(s1)
    80003f04:	b7ed                	j	80003eee <itrunc+0x1c>
    }
  }

  if(ip->addrs[NDIRECT]){
    80003f06:	0809a583          	lw	a1,128(s3)
    80003f0a:	ed91                	bnez	a1,80003f26 <itrunc+0x54>
    brelse(bp);
    bfree(ip->dev, ip->addrs[NDIRECT]);
    ip->addrs[NDIRECT] = 0;
  }

  ip->size = 0;
    80003f0c:	0409a623          	sw	zero,76(s3)
  iupdate(ip);
    80003f10:	854e                	mv	a0,s3
    80003f12:	d51ff0ef          	jal	80003c62 <iupdate>
}
    80003f16:	70a2                	ld	ra,40(sp)
    80003f18:	7402                	ld	s0,32(sp)
    80003f1a:	64e2                	ld	s1,24(sp)
    80003f1c:	6942                	ld	s2,16(sp)
    80003f1e:	69a2                	ld	s3,8(sp)
    80003f20:	6a02                	ld	s4,0(sp)
    80003f22:	6145                	add	sp,sp,48
    80003f24:	8082                	ret
    bp = bread(ip->dev, ip->addrs[NDIRECT]);
    80003f26:	0009a503          	lw	a0,0(s3)
    80003f2a:	cc6ff0ef          	jal	800033f0 <bread>
    80003f2e:	8a2a                	mv	s4,a0
    for(j = 0; j < NINDIRECT; j++){
    80003f30:	05850493          	add	s1,a0,88
    80003f34:	45850913          	add	s2,a0,1112
    80003f38:	a021                	j	80003f40 <itrunc+0x6e>
    80003f3a:	0491                	add	s1,s1,4
    80003f3c:	01248963          	beq	s1,s2,80003f4e <itrunc+0x7c>
      if(a[j])
    80003f40:	408c                	lw	a1,0(s1)
    80003f42:	dde5                	beqz	a1,80003f3a <itrunc+0x68>
        bfree(ip->dev, a[j]);
    80003f44:	0009a503          	lw	a0,0(s3)
    80003f48:	b99ff0ef          	jal	80003ae0 <bfree>
    80003f4c:	b7fd                	j	80003f3a <itrunc+0x68>
    brelse(bp);
    80003f4e:	8552                	mv	a0,s4
    80003f50:	d00ff0ef          	jal	80003450 <brelse>
    bfree(ip->dev, ip->addrs[NDIRECT]);
    80003f54:	0809a583          	lw	a1,128(s3)
    80003f58:	0009a503          	lw	a0,0(s3)
    80003f5c:	b85ff0ef          	jal	80003ae0 <bfree>
    ip->addrs[NDIRECT] = 0;
    80003f60:	0809a023          	sw	zero,128(s3)
    80003f64:	b765                	j	80003f0c <itrunc+0x3a>

0000000080003f66 <iput>:
{
    80003f66:	1101                	add	sp,sp,-32
    80003f68:	ec06                	sd	ra,24(sp)
    80003f6a:	e822                	sd	s0,16(sp)
    80003f6c:	e426                	sd	s1,8(sp)
    80003f6e:	e04a                	sd	s2,0(sp)
    80003f70:	1000                	add	s0,sp,32
    80003f72:	84aa                	mv	s1,a0
  acquire(&itable.lock);
    80003f74:	00012517          	auipc	a0,0x12
    80003f78:	a5450513          	add	a0,a0,-1452 # 800159c8 <itable>
    80003f7c:	8eafe0ef          	jal	80002066 <acquire>
  if(ip->ref == 1 && ip->valid && ip->nlink == 0){
    80003f80:	4498                	lw	a4,8(s1)
    80003f82:	4785                	li	a5,1
    80003f84:	02f70163          	beq	a4,a5,80003fa6 <iput+0x40>
  ip->ref--;
    80003f88:	449c                	lw	a5,8(s1)
    80003f8a:	37fd                	addw	a5,a5,-1
    80003f8c:	c49c                	sw	a5,8(s1)
  release(&itable.lock);
    80003f8e:	00012517          	auipc	a0,0x12
    80003f92:	a3a50513          	add	a0,a0,-1478 # 800159c8 <itable>
    80003f96:	976fe0ef          	jal	8000210c <release>
}
    80003f9a:	60e2                	ld	ra,24(sp)
    80003f9c:	6442                	ld	s0,16(sp)
    80003f9e:	64a2                	ld	s1,8(sp)
    80003fa0:	6902                	ld	s2,0(sp)
    80003fa2:	6105                	add	sp,sp,32
    80003fa4:	8082                	ret
  if(ip->ref == 1 && ip->valid && ip->nlink == 0){
    80003fa6:	40bc                	lw	a5,64(s1)
    80003fa8:	d3e5                	beqz	a5,80003f88 <iput+0x22>
    80003faa:	04a49783          	lh	a5,74(s1)
    80003fae:	ffe9                	bnez	a5,80003f88 <iput+0x22>
    acquiresleep(&ip->lock);
    80003fb0:	01048913          	add	s2,s1,16
    80003fb4:	854a                	mv	a0,s2
    80003fb6:	6b4000ef          	jal	8000466a <acquiresleep>
    release(&itable.lock);
    80003fba:	00012517          	auipc	a0,0x12
    80003fbe:	a0e50513          	add	a0,a0,-1522 # 800159c8 <itable>
    80003fc2:	94afe0ef          	jal	8000210c <release>
    itrunc(ip);
    80003fc6:	8526                	mv	a0,s1
    80003fc8:	f0bff0ef          	jal	80003ed2 <itrunc>
    ip->type = 0;
    80003fcc:	04049223          	sh	zero,68(s1)
    iupdate(ip);
    80003fd0:	8526                	mv	a0,s1
    80003fd2:	c91ff0ef          	jal	80003c62 <iupdate>
    ip->valid = 0;
    80003fd6:	0404a023          	sw	zero,64(s1)
    releasesleep(&ip->lock);
    80003fda:	854a                	mv	a0,s2
    80003fdc:	6d4000ef          	jal	800046b0 <releasesleep>
    acquire(&itable.lock);
    80003fe0:	00012517          	auipc	a0,0x12
    80003fe4:	9e850513          	add	a0,a0,-1560 # 800159c8 <itable>
    80003fe8:	87efe0ef          	jal	80002066 <acquire>
    80003fec:	bf71                	j	80003f88 <iput+0x22>

0000000080003fee <iunlockput>:
{
    80003fee:	1101                	add	sp,sp,-32
    80003ff0:	ec06                	sd	ra,24(sp)
    80003ff2:	e822                	sd	s0,16(sp)
    80003ff4:	e426                	sd	s1,8(sp)
    80003ff6:	1000                	add	s0,sp,32
    80003ff8:	84aa                	mv	s1,a0
  iunlock(ip);
    80003ffa:	dcbff0ef          	jal	80003dc4 <iunlock>
  iput(ip);
    80003ffe:	8526                	mv	a0,s1
    80004000:	f67ff0ef          	jal	80003f66 <iput>
}
    80004004:	60e2                	ld	ra,24(sp)
    80004006:	6442                	ld	s0,16(sp)
    80004008:	64a2                	ld	s1,8(sp)
    8000400a:	6105                	add	sp,sp,32
    8000400c:	8082                	ret

000000008000400e <ireclaim>:
  for (int inum = 1; inum < sb.ninodes; inum++) {
    8000400e:	00012717          	auipc	a4,0x12
    80004012:	9a672703          	lw	a4,-1626(a4) # 800159b4 <sb+0xc>
    80004016:	4785                	li	a5,1
    80004018:	0ae7ff63          	bgeu	a5,a4,800040d6 <ireclaim+0xc8>
{
    8000401c:	7139                	add	sp,sp,-64
    8000401e:	fc06                	sd	ra,56(sp)
    80004020:	f822                	sd	s0,48(sp)
    80004022:	f426                	sd	s1,40(sp)
    80004024:	f04a                	sd	s2,32(sp)
    80004026:	ec4e                	sd	s3,24(sp)
    80004028:	e852                	sd	s4,16(sp)
    8000402a:	e456                	sd	s5,8(sp)
    8000402c:	e05a                	sd	s6,0(sp)
    8000402e:	0080                	add	s0,sp,64
  for (int inum = 1; inum < sb.ninodes; inum++) {
    80004030:	4485                	li	s1,1
    struct buf *bp = bread(dev, IBLOCK(inum, sb));
    80004032:	00050a1b          	sext.w	s4,a0
    80004036:	00012a97          	auipc	s5,0x12
    8000403a:	972a8a93          	add	s5,s5,-1678 # 800159a8 <sb>
      printf("ireclaim: orphaned inode %d\n", inum);
    8000403e:	00002b17          	auipc	s6,0x2
    80004042:	362b0b13          	add	s6,s6,866 # 800063a0 <syscalls+0x3f0>
    80004046:	a099                	j	8000408c <ireclaim+0x7e>
    80004048:	85ce                	mv	a1,s3
    8000404a:	855a                	mv	a0,s6
    8000404c:	b3afc0ef          	jal	80000386 <printf>
      ip = iget(dev, inum);
    80004050:	85ce                	mv	a1,s3
    80004052:	8552                	mv	a0,s4
    80004054:	883ff0ef          	jal	800038d6 <iget>
    80004058:	89aa                	mv	s3,a0
    brelse(bp);
    8000405a:	854a                	mv	a0,s2
    8000405c:	bf4ff0ef          	jal	80003450 <brelse>
    if (ip) {
    80004060:	00098f63          	beqz	s3,8000407e <ireclaim+0x70>
      begin_op();
    80004064:	084010ef          	jal	800050e8 <begin_op>
      ilock(ip);
    80004068:	854e                	mv	a0,s3
    8000406a:	cadff0ef          	jal	80003d16 <ilock>
      iunlock(ip);
    8000406e:	854e                	mv	a0,s3
    80004070:	d55ff0ef          	jal	80003dc4 <iunlock>
      iput(ip);
    80004074:	854e                	mv	a0,s3
    80004076:	ef1ff0ef          	jal	80003f66 <iput>
      end_op();
    8000407a:	0d8010ef          	jal	80005152 <end_op>
  for (int inum = 1; inum < sb.ninodes; inum++) {
    8000407e:	0485                	add	s1,s1,1
    80004080:	00caa703          	lw	a4,12(s5)
    80004084:	0004879b          	sext.w	a5,s1
    80004088:	02e7fd63          	bgeu	a5,a4,800040c2 <ireclaim+0xb4>
    8000408c:	0004899b          	sext.w	s3,s1
    struct buf *bp = bread(dev, IBLOCK(inum, sb));
    80004090:	0044d593          	srl	a1,s1,0x4
    80004094:	018aa783          	lw	a5,24(s5)
    80004098:	9dbd                	addw	a1,a1,a5
    8000409a:	8552                	mv	a0,s4
    8000409c:	b54ff0ef          	jal	800033f0 <bread>
    800040a0:	892a                	mv	s2,a0
    struct dinode *dip = (struct dinode *)bp->data + inum % IPB;
    800040a2:	05850793          	add	a5,a0,88
    800040a6:	00f9f713          	and	a4,s3,15
    800040aa:	071a                	sll	a4,a4,0x6
    800040ac:	97ba                	add	a5,a5,a4
    if (dip->type != 0 && dip->nlink == 0) {  // is an orphaned inode
    800040ae:	00079703          	lh	a4,0(a5)
    800040b2:	c701                	beqz	a4,800040ba <ireclaim+0xac>
    800040b4:	00679783          	lh	a5,6(a5)
    800040b8:	dbc1                	beqz	a5,80004048 <ireclaim+0x3a>
    brelse(bp);
    800040ba:	854a                	mv	a0,s2
    800040bc:	b94ff0ef          	jal	80003450 <brelse>
    if (ip) {
    800040c0:	bf7d                	j	8000407e <ireclaim+0x70>
}
    800040c2:	70e2                	ld	ra,56(sp)
    800040c4:	7442                	ld	s0,48(sp)
    800040c6:	74a2                	ld	s1,40(sp)
    800040c8:	7902                	ld	s2,32(sp)
    800040ca:	69e2                	ld	s3,24(sp)
    800040cc:	6a42                	ld	s4,16(sp)
    800040ce:	6aa2                	ld	s5,8(sp)
    800040d0:	6b02                	ld	s6,0(sp)
    800040d2:	6121                	add	sp,sp,64
    800040d4:	8082                	ret
    800040d6:	8082                	ret

00000000800040d8 <fsinit>:
fsinit(int dev) {
    800040d8:	1101                	add	sp,sp,-32
    800040da:	ec06                	sd	ra,24(sp)
    800040dc:	e822                	sd	s0,16(sp)
    800040de:	e426                	sd	s1,8(sp)
    800040e0:	e04a                	sd	s2,0(sp)
    800040e2:	1000                	add	s0,sp,32
    800040e4:	84aa                	mv	s1,a0
  readsb(dev, &sb);
    800040e6:	00012917          	auipc	s2,0x12
    800040ea:	8c290913          	add	s2,s2,-1854 # 800159a8 <sb>
    800040ee:	85ca                	mv	a1,s2
    800040f0:	895ff0ef          	jal	80003984 <readsb>
  if(sb.magic != FSMAGIC)
    800040f4:	00092703          	lw	a4,0(s2)
    800040f8:	102037b7          	lui	a5,0x10203
    800040fc:	04078793          	add	a5,a5,64 # 10203040 <_entry-0x6fdfcfc0>
    80004100:	02f71263          	bne	a4,a5,80004124 <fsinit+0x4c>
  initlog(dev, &sb);
    80004104:	00012597          	auipc	a1,0x12
    80004108:	8a458593          	add	a1,a1,-1884 # 800159a8 <sb>
    8000410c:	8526                	mv	a0,s1
    8000410e:	75d000ef          	jal	8000506a <initlog>
  ireclaim(dev);
    80004112:	8526                	mv	a0,s1
    80004114:	efbff0ef          	jal	8000400e <ireclaim>
}
    80004118:	60e2                	ld	ra,24(sp)
    8000411a:	6442                	ld	s0,16(sp)
    8000411c:	64a2                	ld	s1,8(sp)
    8000411e:	6902                	ld	s2,0(sp)
    80004120:	6105                	add	sp,sp,32
    80004122:	8082                	ret
    panic("invalid file system");
    80004124:	00002517          	auipc	a0,0x2
    80004128:	29c50513          	add	a0,a0,668 # 800063c0 <syscalls+0x410>
    8000412c:	875fc0ef          	jal	800009a0 <panic>
    80004130:	bfd1                	j	80004104 <fsinit+0x2c>

0000000080004132 <stati>:

// Copy stat information from inode.
// Caller must hold ip->lock.
void
stati(struct inode *ip, struct stat *st)
{
    80004132:	1141                	add	sp,sp,-16
    80004134:	e422                	sd	s0,8(sp)
    80004136:	0800                	add	s0,sp,16
  st->dev = ip->dev;
    80004138:	411c                	lw	a5,0(a0)
    8000413a:	c19c                	sw	a5,0(a1)
  st->ino = ip->inum;
    8000413c:	415c                	lw	a5,4(a0)
    8000413e:	c1dc                	sw	a5,4(a1)
  st->type = ip->type;
    80004140:	04451783          	lh	a5,68(a0)
    80004144:	00f59423          	sh	a5,8(a1)
  st->nlink = ip->nlink;
    80004148:	04a51783          	lh	a5,74(a0)
    8000414c:	00f59523          	sh	a5,10(a1)
  st->size = ip->size;
    80004150:	04c56783          	lwu	a5,76(a0)
    80004154:	e99c                	sd	a5,16(a1)
}
    80004156:	6422                	ld	s0,8(sp)
    80004158:	0141                	add	sp,sp,16
    8000415a:	8082                	ret

000000008000415c <readi>:
readi(struct inode *ip, int user_dst, uint64 dst, uint32 off, uint32 n)
{
  uint32 tot, m;
  struct buf *bp;

  if(off > ip->size || off + n < off)
    8000415c:	457c                	lw	a5,76(a0)
    8000415e:	0cd7ef63          	bltu	a5,a3,8000423c <readi+0xe0>
{
    80004162:	7159                	add	sp,sp,-112
    80004164:	f486                	sd	ra,104(sp)
    80004166:	f0a2                	sd	s0,96(sp)
    80004168:	eca6                	sd	s1,88(sp)
    8000416a:	e8ca                	sd	s2,80(sp)
    8000416c:	e4ce                	sd	s3,72(sp)
    8000416e:	e0d2                	sd	s4,64(sp)
    80004170:	fc56                	sd	s5,56(sp)
    80004172:	f85a                	sd	s6,48(sp)
    80004174:	f45e                	sd	s7,40(sp)
    80004176:	f062                	sd	s8,32(sp)
    80004178:	ec66                	sd	s9,24(sp)
    8000417a:	e86a                	sd	s10,16(sp)
    8000417c:	e46e                	sd	s11,8(sp)
    8000417e:	1880                	add	s0,sp,112
    80004180:	8b2a                	mv	s6,a0
    80004182:	8bae                	mv	s7,a1
    80004184:	8a32                	mv	s4,a2
    80004186:	84b6                	mv	s1,a3
    80004188:	8aba                	mv	s5,a4
  if(off > ip->size || off + n < off)
    8000418a:	9f35                	addw	a4,a4,a3
    return 0;
    8000418c:	4501                	li	a0,0
  if(off > ip->size || off + n < off)
    8000418e:	08d76663          	bltu	a4,a3,8000421a <readi+0xbe>
  if(off + n > ip->size)
    80004192:	00e7f463          	bgeu	a5,a4,8000419a <readi+0x3e>
    n = ip->size - off;
    80004196:	40d78abb          	subw	s5,a5,a3

  for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
    8000419a:	080a8f63          	beqz	s5,80004238 <readi+0xdc>
    8000419e:	4981                	li	s3,0
    uint32 addr = bmap(ip, off/BSIZE);
    if(addr == 0)
      break;
    bp = bread(ip->dev, addr);
    m = min(n - tot, BSIZE - off%BSIZE);
    800041a0:	40000c93          	li	s9,1024
    if(either_copyout(user_dst, dst, bp->data + (off % BSIZE), m) == -1) {
    800041a4:	5c7d                	li	s8,-1
    800041a6:	a80d                	j	800041d8 <readi+0x7c>
    800041a8:	020d1d93          	sll	s11,s10,0x20
    800041ac:	020ddd93          	srl	s11,s11,0x20
    800041b0:	05890613          	add	a2,s2,88
    800041b4:	86ee                	mv	a3,s11
    800041b6:	963a                	add	a2,a2,a4
    800041b8:	85d2                	mv	a1,s4
    800041ba:	855e                	mv	a0,s7
    800041bc:	af9fe0ef          	jal	80002cb4 <either_copyout>
    800041c0:	05850763          	beq	a0,s8,8000420e <readi+0xb2>
      brelse(bp);
      tot = -1;
      break;
    }
    brelse(bp);
    800041c4:	854a                	mv	a0,s2
    800041c6:	a8aff0ef          	jal	80003450 <brelse>
  for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
    800041ca:	013d09bb          	addw	s3,s10,s3
    800041ce:	009d04bb          	addw	s1,s10,s1
    800041d2:	9a6e                	add	s4,s4,s11
    800041d4:	0559f163          	bgeu	s3,s5,80004216 <readi+0xba>
    uint32 addr = bmap(ip, off/BSIZE);
    800041d8:	00a4d59b          	srlw	a1,s1,0xa
    800041dc:	855a                	mv	a0,s6
    800041de:	c21ff0ef          	jal	80003dfe <bmap>
    800041e2:	0005059b          	sext.w	a1,a0
    if(addr == 0)
    800041e6:	c985                	beqz	a1,80004216 <readi+0xba>
    bp = bread(ip->dev, addr);
    800041e8:	000b2503          	lw	a0,0(s6)
    800041ec:	a04ff0ef          	jal	800033f0 <bread>
    800041f0:	892a                	mv	s2,a0
    m = min(n - tot, BSIZE - off%BSIZE);
    800041f2:	3ff4f713          	and	a4,s1,1023
    800041f6:	40ec87bb          	subw	a5,s9,a4
    800041fa:	413a86bb          	subw	a3,s5,s3
    800041fe:	8d3e                	mv	s10,a5
    80004200:	2781                	sext.w	a5,a5
    80004202:	0006861b          	sext.w	a2,a3
    80004206:	faf671e3          	bgeu	a2,a5,800041a8 <readi+0x4c>
    8000420a:	8d36                	mv	s10,a3
    8000420c:	bf71                	j	800041a8 <readi+0x4c>
      brelse(bp);
    8000420e:	854a                	mv	a0,s2
    80004210:	a40ff0ef          	jal	80003450 <brelse>
      tot = -1;
    80004214:	59fd                	li	s3,-1
  }
  return tot;
    80004216:	0009851b          	sext.w	a0,s3
}
    8000421a:	70a6                	ld	ra,104(sp)
    8000421c:	7406                	ld	s0,96(sp)
    8000421e:	64e6                	ld	s1,88(sp)
    80004220:	6946                	ld	s2,80(sp)
    80004222:	69a6                	ld	s3,72(sp)
    80004224:	6a06                	ld	s4,64(sp)
    80004226:	7ae2                	ld	s5,56(sp)
    80004228:	7b42                	ld	s6,48(sp)
    8000422a:	7ba2                	ld	s7,40(sp)
    8000422c:	7c02                	ld	s8,32(sp)
    8000422e:	6ce2                	ld	s9,24(sp)
    80004230:	6d42                	ld	s10,16(sp)
    80004232:	6da2                	ld	s11,8(sp)
    80004234:	6165                	add	sp,sp,112
    80004236:	8082                	ret
  for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
    80004238:	89d6                	mv	s3,s5
    8000423a:	bff1                	j	80004216 <readi+0xba>
    return 0;
    8000423c:	4501                	li	a0,0
}
    8000423e:	8082                	ret

0000000080004240 <writei>:
writei(struct inode *ip, int user_src, uint64 src, uint32 off, uint32 n)
{
  uint32 tot, m;
  struct buf *bp;

  if(off > ip->size || off + n < off)
    80004240:	457c                	lw	a5,76(a0)
    80004242:	0ed7ea63          	bltu	a5,a3,80004336 <writei+0xf6>
{
    80004246:	7159                	add	sp,sp,-112
    80004248:	f486                	sd	ra,104(sp)
    8000424a:	f0a2                	sd	s0,96(sp)
    8000424c:	eca6                	sd	s1,88(sp)
    8000424e:	e8ca                	sd	s2,80(sp)
    80004250:	e4ce                	sd	s3,72(sp)
    80004252:	e0d2                	sd	s4,64(sp)
    80004254:	fc56                	sd	s5,56(sp)
    80004256:	f85a                	sd	s6,48(sp)
    80004258:	f45e                	sd	s7,40(sp)
    8000425a:	f062                	sd	s8,32(sp)
    8000425c:	ec66                	sd	s9,24(sp)
    8000425e:	e86a                	sd	s10,16(sp)
    80004260:	e46e                	sd	s11,8(sp)
    80004262:	1880                	add	s0,sp,112
    80004264:	8aaa                	mv	s5,a0
    80004266:	8bae                	mv	s7,a1
    80004268:	8a32                	mv	s4,a2
    8000426a:	8936                	mv	s2,a3
    8000426c:	8b3a                	mv	s6,a4
  if(off > ip->size || off + n < off)
    8000426e:	00e687bb          	addw	a5,a3,a4
    80004272:	0cd7e463          	bltu	a5,a3,8000433a <writei+0xfa>
    return -1;
  if(off + n > MAXFILE*BSIZE)
    80004276:	00043737          	lui	a4,0x43
    8000427a:	0cf76263          	bltu	a4,a5,8000433e <writei+0xfe>
    return -1;

  for(tot=0; tot<n; tot+=m, off+=m, src+=m){
    8000427e:	0a0b0a63          	beqz	s6,80004332 <writei+0xf2>
    80004282:	4981                	li	s3,0
    uint32 addr = bmap(ip, off/BSIZE);
    if(addr == 0)
      break;
    bp = bread(ip->dev, addr);
    m = min(n - tot, BSIZE - off%BSIZE);
    80004284:	40000c93          	li	s9,1024
    if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
    80004288:	5c7d                	li	s8,-1
    8000428a:	a825                	j	800042c2 <writei+0x82>
    8000428c:	020d1d93          	sll	s11,s10,0x20
    80004290:	020ddd93          	srl	s11,s11,0x20
    80004294:	05848513          	add	a0,s1,88
    80004298:	86ee                	mv	a3,s11
    8000429a:	8652                	mv	a2,s4
    8000429c:	85de                	mv	a1,s7
    8000429e:	953a                	add	a0,a0,a4
    800042a0:	a6bfe0ef          	jal	80002d0a <either_copyin>
    800042a4:	05850a63          	beq	a0,s8,800042f8 <writei+0xb8>
      brelse(bp);
      break;
    }
    log_write(bp);
    800042a8:	8526                	mv	a0,s1
    800042aa:	7c3000ef          	jal	8000526c <log_write>
    brelse(bp);
    800042ae:	8526                	mv	a0,s1
    800042b0:	9a0ff0ef          	jal	80003450 <brelse>
  for(tot=0; tot<n; tot+=m, off+=m, src+=m){
    800042b4:	013d09bb          	addw	s3,s10,s3
    800042b8:	012d093b          	addw	s2,s10,s2
    800042bc:	9a6e                	add	s4,s4,s11
    800042be:	0569f063          	bgeu	s3,s6,800042fe <writei+0xbe>
    uint32 addr = bmap(ip, off/BSIZE);
    800042c2:	00a9559b          	srlw	a1,s2,0xa
    800042c6:	8556                	mv	a0,s5
    800042c8:	b37ff0ef          	jal	80003dfe <bmap>
    800042cc:	0005059b          	sext.w	a1,a0
    if(addr == 0)
    800042d0:	c59d                	beqz	a1,800042fe <writei+0xbe>
    bp = bread(ip->dev, addr);
    800042d2:	000aa503          	lw	a0,0(s5)
    800042d6:	91aff0ef          	jal	800033f0 <bread>
    800042da:	84aa                	mv	s1,a0
    m = min(n - tot, BSIZE - off%BSIZE);
    800042dc:	3ff97713          	and	a4,s2,1023
    800042e0:	40ec87bb          	subw	a5,s9,a4
    800042e4:	413b06bb          	subw	a3,s6,s3
    800042e8:	8d3e                	mv	s10,a5
    800042ea:	2781                	sext.w	a5,a5
    800042ec:	0006861b          	sext.w	a2,a3
    800042f0:	f8f67ee3          	bgeu	a2,a5,8000428c <writei+0x4c>
    800042f4:	8d36                	mv	s10,a3
    800042f6:	bf59                	j	8000428c <writei+0x4c>
      brelse(bp);
    800042f8:	8526                	mv	a0,s1
    800042fa:	956ff0ef          	jal	80003450 <brelse>
  }

  if(off > ip->size)
    800042fe:	04caa783          	lw	a5,76(s5)
    80004302:	0127f463          	bgeu	a5,s2,8000430a <writei+0xca>
    ip->size = off;
    80004306:	052aa623          	sw	s2,76(s5)

  // write the i-node back to disk even if the size didn't change
  // because the loop above might have called bmap() and added a new
  // block to ip->addrs[].
  iupdate(ip);
    8000430a:	8556                	mv	a0,s5
    8000430c:	957ff0ef          	jal	80003c62 <iupdate>

  return tot;
    80004310:	0009851b          	sext.w	a0,s3
}
    80004314:	70a6                	ld	ra,104(sp)
    80004316:	7406                	ld	s0,96(sp)
    80004318:	64e6                	ld	s1,88(sp)
    8000431a:	6946                	ld	s2,80(sp)
    8000431c:	69a6                	ld	s3,72(sp)
    8000431e:	6a06                	ld	s4,64(sp)
    80004320:	7ae2                	ld	s5,56(sp)
    80004322:	7b42                	ld	s6,48(sp)
    80004324:	7ba2                	ld	s7,40(sp)
    80004326:	7c02                	ld	s8,32(sp)
    80004328:	6ce2                	ld	s9,24(sp)
    8000432a:	6d42                	ld	s10,16(sp)
    8000432c:	6da2                	ld	s11,8(sp)
    8000432e:	6165                	add	sp,sp,112
    80004330:	8082                	ret
  for(tot=0; tot<n; tot+=m, off+=m, src+=m){
    80004332:	89da                	mv	s3,s6
    80004334:	bfd9                	j	8000430a <writei+0xca>
    return -1;
    80004336:	557d                	li	a0,-1
}
    80004338:	8082                	ret
    return -1;
    8000433a:	557d                	li	a0,-1
    8000433c:	bfe1                	j	80004314 <writei+0xd4>
    return -1;
    8000433e:	557d                	li	a0,-1
    80004340:	bfd1                	j	80004314 <writei+0xd4>

0000000080004342 <namecmp>:

// Directories

int
namecmp(const char *s, const char *t)
{
    80004342:	1141                	add	sp,sp,-16
    80004344:	e406                	sd	ra,8(sp)
    80004346:	e022                	sd	s0,0(sp)
    80004348:	0800                	add	s0,sp,16
  return strncmp(s, t, DIRSIZ);
    8000434a:	4639                	li	a2,14
    8000434c:	0ba010ef          	jal	80005406 <strncmp>
}
    80004350:	60a2                	ld	ra,8(sp)
    80004352:	6402                	ld	s0,0(sp)
    80004354:	0141                	add	sp,sp,16
    80004356:	8082                	ret

0000000080004358 <dirlookup>:

// Look for a directory entry in a directory.
// If found, set *poff to byte offset of entry.
struct inode*
dirlookup(struct inode *dp, char *name, uint32 *poff)
{
    80004358:	715d                	add	sp,sp,-80
    8000435a:	e486                	sd	ra,72(sp)
    8000435c:	e0a2                	sd	s0,64(sp)
    8000435e:	fc26                	sd	s1,56(sp)
    80004360:	f84a                	sd	s2,48(sp)
    80004362:	f44e                	sd	s3,40(sp)
    80004364:	f052                	sd	s4,32(sp)
    80004366:	ec56                	sd	s5,24(sp)
    80004368:	0880                	add	s0,sp,80
    8000436a:	892a                	mv	s2,a0
    8000436c:	89ae                	mv	s3,a1
    8000436e:	8ab2                	mv	s5,a2
  uint32 off, inum;
  struct dirent de;

  if(dp->type != T_DIR)
    80004370:	04451703          	lh	a4,68(a0)
    80004374:	4785                	li	a5,1
    80004376:	00f71b63          	bne	a4,a5,8000438c <dirlookup+0x34>
    panic("dirlookup not DIR");

  for(off = 0; off < dp->size; off += sizeof(de)){
    8000437a:	04c92783          	lw	a5,76(s2)
    8000437e:	c3c1                	beqz	a5,800043fe <dirlookup+0xa6>
    80004380:	4481                	li	s1,0
    if(readi(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de))
      panic("dirlookup read");
    80004382:	00002a17          	auipc	s4,0x2
    80004386:	06ea0a13          	add	s4,s4,110 # 800063f0 <syscalls+0x440>
    8000438a:	a00d                	j	800043ac <dirlookup+0x54>
    panic("dirlookup not DIR");
    8000438c:	00002517          	auipc	a0,0x2
    80004390:	04c50513          	add	a0,a0,76 # 800063d8 <syscalls+0x428>
    80004394:	e0cfc0ef          	jal	800009a0 <panic>
    80004398:	b7cd                	j	8000437a <dirlookup+0x22>
      panic("dirlookup read");
    8000439a:	8552                	mv	a0,s4
    8000439c:	e04fc0ef          	jal	800009a0 <panic>
    800043a0:	a00d                	j	800043c2 <dirlookup+0x6a>
  for(off = 0; off < dp->size; off += sizeof(de)){
    800043a2:	24c1                	addw	s1,s1,16
    800043a4:	04c92783          	lw	a5,76(s2)
    800043a8:	04f4f163          	bgeu	s1,a5,800043ea <dirlookup+0x92>
    if(readi(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de))
    800043ac:	4741                	li	a4,16
    800043ae:	86a6                	mv	a3,s1
    800043b0:	fb040613          	add	a2,s0,-80
    800043b4:	4581                	li	a1,0
    800043b6:	854a                	mv	a0,s2
    800043b8:	da5ff0ef          	jal	8000415c <readi>
    800043bc:	47c1                	li	a5,16
    800043be:	fcf51ee3          	bne	a0,a5,8000439a <dirlookup+0x42>
    if(de.inum == 0)
    800043c2:	fb045783          	lhu	a5,-80(s0)
    800043c6:	dff1                	beqz	a5,800043a2 <dirlookup+0x4a>
      continue;
    if(namecmp(name, de.name) == 0){
    800043c8:	fb240593          	add	a1,s0,-78
    800043cc:	854e                	mv	a0,s3
    800043ce:	f75ff0ef          	jal	80004342 <namecmp>
    800043d2:	f961                	bnez	a0,800043a2 <dirlookup+0x4a>
      // entry matches path element
      if(poff)
    800043d4:	000a8463          	beqz	s5,800043dc <dirlookup+0x84>
        *poff = off;
    800043d8:	009aa023          	sw	s1,0(s5)
      inum = de.inum;
      return iget(dp->dev, inum);
    800043dc:	fb045583          	lhu	a1,-80(s0)
    800043e0:	00092503          	lw	a0,0(s2)
    800043e4:	cf2ff0ef          	jal	800038d6 <iget>
    800043e8:	a011                	j	800043ec <dirlookup+0x94>
    }
  }

  return 0;
    800043ea:	4501                	li	a0,0
}
    800043ec:	60a6                	ld	ra,72(sp)
    800043ee:	6406                	ld	s0,64(sp)
    800043f0:	74e2                	ld	s1,56(sp)
    800043f2:	7942                	ld	s2,48(sp)
    800043f4:	79a2                	ld	s3,40(sp)
    800043f6:	7a02                	ld	s4,32(sp)
    800043f8:	6ae2                	ld	s5,24(sp)
    800043fa:	6161                	add	sp,sp,80
    800043fc:	8082                	ret
  return 0;
    800043fe:	4501                	li	a0,0
    80004400:	b7f5                	j	800043ec <dirlookup+0x94>

0000000080004402 <dirlink>:

// Write a new directory entry (name, inum) into the directory dp.
// Returns 0 on success, -1 on failure (e.g. out of disk blocks).
int
dirlink(struct inode *dp, char *name, uint32 inum)
{
    80004402:	715d                	add	sp,sp,-80
    80004404:	e486                	sd	ra,72(sp)
    80004406:	e0a2                	sd	s0,64(sp)
    80004408:	fc26                	sd	s1,56(sp)
    8000440a:	f84a                	sd	s2,48(sp)
    8000440c:	f44e                	sd	s3,40(sp)
    8000440e:	f052                	sd	s4,32(sp)
    80004410:	ec56                	sd	s5,24(sp)
    80004412:	0880                	add	s0,sp,80
    80004414:	892a                	mv	s2,a0
    80004416:	8a2e                	mv	s4,a1
    80004418:	8ab2                	mv	s5,a2
  int off;
  struct dirent de;
  struct inode *ip;

  // Check that name is not present.
  if((ip = dirlookup(dp, name, 0)) != 0){
    8000441a:	4601                	li	a2,0
    8000441c:	f3dff0ef          	jal	80004358 <dirlookup>
    80004420:	e911                	bnez	a0,80004434 <dirlink+0x32>
    iput(ip);
    return -1;
  }

  // Look for an empty dirent.
  for(off = 0; off < dp->size; off += sizeof(de)){
    80004422:	04c92483          	lw	s1,76(s2)
    80004426:	c0b1                	beqz	s1,8000446a <dirlink+0x68>
    80004428:	4481                	li	s1,0
    if(readi(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de))
      panic("dirlink read");
    8000442a:	00002997          	auipc	s3,0x2
    8000442e:	fd698993          	add	s3,s3,-42 # 80006400 <syscalls+0x450>
    80004432:	a829                	j	8000444c <dirlink+0x4a>
    iput(ip);
    80004434:	b33ff0ef          	jal	80003f66 <iput>
    return -1;
    80004438:	557d                	li	a0,-1
    8000443a:	a8a9                	j	80004494 <dirlink+0x92>
    if(de.inum == 0)
    8000443c:	fb045783          	lhu	a5,-80(s0)
    80004440:	c78d                	beqz	a5,8000446a <dirlink+0x68>
  for(off = 0; off < dp->size; off += sizeof(de)){
    80004442:	24c1                	addw	s1,s1,16
    80004444:	04c92783          	lw	a5,76(s2)
    80004448:	02f4f163          	bgeu	s1,a5,8000446a <dirlink+0x68>
    if(readi(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de))
    8000444c:	4741                	li	a4,16
    8000444e:	86a6                	mv	a3,s1
    80004450:	fb040613          	add	a2,s0,-80
    80004454:	4581                	li	a1,0
    80004456:	854a                	mv	a0,s2
    80004458:	d05ff0ef          	jal	8000415c <readi>
    8000445c:	47c1                	li	a5,16
    8000445e:	fcf50fe3          	beq	a0,a5,8000443c <dirlink+0x3a>
      panic("dirlink read");
    80004462:	854e                	mv	a0,s3
    80004464:	d3cfc0ef          	jal	800009a0 <panic>
    80004468:	bfd1                	j	8000443c <dirlink+0x3a>
      break;
  }

  strncpy(de.name, name, DIRSIZ);
    8000446a:	4639                	li	a2,14
    8000446c:	85d2                	mv	a1,s4
    8000446e:	fb240513          	add	a0,s0,-78
    80004472:	7d1000ef          	jal	80005442 <strncpy>
  de.inum = inum;
    80004476:	fb541823          	sh	s5,-80(s0)
  if(writei(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de))
    8000447a:	4741                	li	a4,16
    8000447c:	86a6                	mv	a3,s1
    8000447e:	fb040613          	add	a2,s0,-80
    80004482:	4581                	li	a1,0
    80004484:	854a                	mv	a0,s2
    80004486:	dbbff0ef          	jal	80004240 <writei>
    8000448a:	1541                	add	a0,a0,-16
    8000448c:	00a03533          	snez	a0,a0
    80004490:	40a00533          	neg	a0,a0
    return -1;

  return 0;
}
    80004494:	60a6                	ld	ra,72(sp)
    80004496:	6406                	ld	s0,64(sp)
    80004498:	74e2                	ld	s1,56(sp)
    8000449a:	7942                	ld	s2,48(sp)
    8000449c:	79a2                	ld	s3,40(sp)
    8000449e:	7a02                	ld	s4,32(sp)
    800044a0:	6ae2                	ld	s5,24(sp)
    800044a2:	6161                	add	sp,sp,80
    800044a4:	8082                	ret

00000000800044a6 <skipelem>:
//   skipelem("a", name) = "", setting name = "a"
//   skipelem("", name) = skipelem("////", name) = 0
//
 char*
skipelem(char *path, char *name)
{
    800044a6:	7179                	add	sp,sp,-48
    800044a8:	f406                	sd	ra,40(sp)
    800044aa:	f022                	sd	s0,32(sp)
    800044ac:	ec26                	sd	s1,24(sp)
    800044ae:	e84a                	sd	s2,16(sp)
    800044b0:	e44e                	sd	s3,8(sp)
    800044b2:	1800                	add	s0,sp,48
    800044b4:	892e                	mv	s2,a1
  char *s;
  int len;

  while(*path == '/')
    800044b6:	00054783          	lbu	a5,0(a0)
    800044ba:	02f00713          	li	a4,47
    800044be:	00e79763          	bne	a5,a4,800044cc <skipelem+0x26>
    path++;
    800044c2:	0505                	add	a0,a0,1
  while(*path == '/')
    800044c4:	00054783          	lbu	a5,0(a0)
    800044c8:	fee78de3          	beq	a5,a4,800044c2 <skipelem+0x1c>
  if(*path == 0)
    800044cc:	cfa5                	beqz	a5,80004544 <skipelem+0x9e>
    return 0;
  s = path;
  while(*path != '/' && *path != 0)
    800044ce:	00054783          	lbu	a5,0(a0)
    800044d2:	02f00693          	li	a3,47
    800044d6:	84aa                	mv	s1,a0
    800044d8:	02f00713          	li	a4,47
    path++;
  len = path - s;
    800044dc:	4981                	li	s3,0
    800044de:	4601                	li	a2,0
  while(*path != '/' && *path != 0)
    800044e0:	04d78963          	beq	a5,a3,80004532 <skipelem+0x8c>
    800044e4:	c791                	beqz	a5,800044f0 <skipelem+0x4a>
    path++;
    800044e6:	0485                	add	s1,s1,1
  while(*path != '/' && *path != 0)
    800044e8:	0004c783          	lbu	a5,0(s1)
    800044ec:	fee79ce3          	bne	a5,a4,800044e4 <skipelem+0x3e>
  len = path - s;
    800044f0:	40a48633          	sub	a2,s1,a0
    800044f4:	0006099b          	sext.w	s3,a2
  if(len >= DIRSIZ)
    800044f8:	47b5                	li	a5,13
    800044fa:	0337dc63          	bge	a5,s3,80004532 <skipelem+0x8c>
    memmove(name, s, DIRSIZ);
    800044fe:	4639                	li	a2,14
    80004500:	85aa                	mv	a1,a0
    80004502:	854a                	mv	a0,s2
    80004504:	693000ef          	jal	80005396 <memmove>
  else {
    memmove(name, s, len);
    name[len] = 0;
  }
  while(*path == '/')
    80004508:	0004c703          	lbu	a4,0(s1)
    8000450c:	02f00793          	li	a5,47
    80004510:	00f71963          	bne	a4,a5,80004522 <skipelem+0x7c>
    80004514:	02f00713          	li	a4,47
    path++;
    80004518:	0485                	add	s1,s1,1
  while(*path == '/')
    8000451a:	0004c783          	lbu	a5,0(s1)
    8000451e:	fee78de3          	beq	a5,a4,80004518 <skipelem+0x72>
  return path;
}
    80004522:	8526                	mv	a0,s1
    80004524:	70a2                	ld	ra,40(sp)
    80004526:	7402                	ld	s0,32(sp)
    80004528:	64e2                	ld	s1,24(sp)
    8000452a:	6942                	ld	s2,16(sp)
    8000452c:	69a2                	ld	s3,8(sp)
    8000452e:	6145                	add	sp,sp,48
    80004530:	8082                	ret
    memmove(name, s, len);
    80004532:	2601                	sext.w	a2,a2
    80004534:	85aa                	mv	a1,a0
    80004536:	854a                	mv	a0,s2
    80004538:	65f000ef          	jal	80005396 <memmove>
    name[len] = 0;
    8000453c:	994e                	add	s2,s2,s3
    8000453e:	00090023          	sb	zero,0(s2)
    80004542:	b7d9                	j	80004508 <skipelem+0x62>
    return 0;
    80004544:	4481                	li	s1,0
    80004546:	bff1                	j	80004522 <skipelem+0x7c>

0000000080004548 <namex>:
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
// Must be called inside a transaction since it calls iput().
struct inode*
namex(char *path, int nameiparent, char *name)
{
    80004548:	7139                	add	sp,sp,-64
    8000454a:	fc06                	sd	ra,56(sp)
    8000454c:	f822                	sd	s0,48(sp)
    8000454e:	f426                	sd	s1,40(sp)
    80004550:	f04a                	sd	s2,32(sp)
    80004552:	ec4e                	sd	s3,24(sp)
    80004554:	e852                	sd	s4,16(sp)
    80004556:	e456                	sd	s5,8(sp)
    80004558:	e05a                	sd	s6,0(sp)
    8000455a:	0080                	add	s0,sp,64
    8000455c:	84aa                	mv	s1,a0
    8000455e:	8aae                	mv	s5,a1
    80004560:	8a32                	mv	s4,a2
  struct inode *ip, *next;

  if(*path == '/')
    80004562:	00054703          	lbu	a4,0(a0)
    80004566:	02f00793          	li	a5,47
    8000456a:	00f70a63          	beq	a4,a5,8000457e <namex+0x36>
    ip = iget(ROOTDEV, ROOTINO);
  else
    ip = idup(myproc()->cwd);
    8000456e:	ff5fd0ef          	jal	80002562 <myproc>
    80004572:	7168                	ld	a0,224(a0)
    80004574:	f6cff0ef          	jal	80003ce0 <idup>
    80004578:	892a                	mv	s2,a0

  while((path = skipelem(path, name)) != 0){
    ilock(ip);
    if(ip->type != T_DIR){
    8000457a:	4b05                	li	s6,1
    8000457c:	a089                	j	800045be <namex+0x76>
    ip = iget(ROOTDEV, ROOTINO);
    8000457e:	4585                	li	a1,1
    80004580:	4505                	li	a0,1
    80004582:	b54ff0ef          	jal	800038d6 <iget>
    80004586:	892a                	mv	s2,a0
    80004588:	bfcd                	j	8000457a <namex+0x32>
      iunlockput(ip);
    8000458a:	854a                	mv	a0,s2
    8000458c:	a63ff0ef          	jal	80003fee <iunlockput>
      return 0;
    80004590:	4901                	li	s2,0
  if(nameiparent){
    iput(ip);
    return 0;
  }
  return ip;
}
    80004592:	854a                	mv	a0,s2
    80004594:	70e2                	ld	ra,56(sp)
    80004596:	7442                	ld	s0,48(sp)
    80004598:	74a2                	ld	s1,40(sp)
    8000459a:	7902                	ld	s2,32(sp)
    8000459c:	69e2                	ld	s3,24(sp)
    8000459e:	6a42                	ld	s4,16(sp)
    800045a0:	6aa2                	ld	s5,8(sp)
    800045a2:	6b02                	ld	s6,0(sp)
    800045a4:	6121                	add	sp,sp,64
    800045a6:	8082                	ret
    if((next = dirlookup(ip, name, 0)) == 0){
    800045a8:	4601                	li	a2,0
    800045aa:	85d2                	mv	a1,s4
    800045ac:	854a                	mv	a0,s2
    800045ae:	dabff0ef          	jal	80004358 <dirlookup>
    800045b2:	89aa                	mv	s3,a0
    800045b4:	c91d                	beqz	a0,800045ea <namex+0xa2>
    iunlockput(ip);
    800045b6:	854a                	mv	a0,s2
    800045b8:	a37ff0ef          	jal	80003fee <iunlockput>
    ip = next;
    800045bc:	894e                	mv	s2,s3
  while((path = skipelem(path, name)) != 0){
    800045be:	85d2                	mv	a1,s4
    800045c0:	8526                	mv	a0,s1
    800045c2:	ee5ff0ef          	jal	800044a6 <skipelem>
    800045c6:	84aa                	mv	s1,a0
    800045c8:	c515                	beqz	a0,800045f4 <namex+0xac>
    ilock(ip);
    800045ca:	854a                	mv	a0,s2
    800045cc:	f4aff0ef          	jal	80003d16 <ilock>
    if(ip->type != T_DIR){
    800045d0:	04491783          	lh	a5,68(s2)
    800045d4:	fb679be3          	bne	a5,s6,8000458a <namex+0x42>
    if(nameiparent && *path == '\0'){
    800045d8:	fc0a88e3          	beqz	s5,800045a8 <namex+0x60>
    800045dc:	0004c783          	lbu	a5,0(s1)
    800045e0:	f7e1                	bnez	a5,800045a8 <namex+0x60>
      iunlock(ip);
    800045e2:	854a                	mv	a0,s2
    800045e4:	fe0ff0ef          	jal	80003dc4 <iunlock>
      return ip;
    800045e8:	b76d                	j	80004592 <namex+0x4a>
      iunlockput(ip);
    800045ea:	854a                	mv	a0,s2
    800045ec:	a03ff0ef          	jal	80003fee <iunlockput>
      return 0;
    800045f0:	894e                	mv	s2,s3
    800045f2:	b745                	j	80004592 <namex+0x4a>
  if(nameiparent){
    800045f4:	f80a8fe3          	beqz	s5,80004592 <namex+0x4a>
    iput(ip);
    800045f8:	854a                	mv	a0,s2
    800045fa:	96dff0ef          	jal	80003f66 <iput>
    return 0;
    800045fe:	8926                	mv	s2,s1
    80004600:	bf49                	j	80004592 <namex+0x4a>

0000000080004602 <namei>:

struct inode*
namei(char *path)
{
    80004602:	1101                	add	sp,sp,-32
    80004604:	ec06                	sd	ra,24(sp)
    80004606:	e822                	sd	s0,16(sp)
    80004608:	1000                	add	s0,sp,32
  char name[DIRSIZ];
  return namex(path, 0, name);
    8000460a:	fe040613          	add	a2,s0,-32
    8000460e:	4581                	li	a1,0
    80004610:	f39ff0ef          	jal	80004548 <namex>
}
    80004614:	60e2                	ld	ra,24(sp)
    80004616:	6442                	ld	s0,16(sp)
    80004618:	6105                	add	sp,sp,32
    8000461a:	8082                	ret

000000008000461c <nameiparent>:

struct inode*
nameiparent(char *path, char *name)
{
    8000461c:	1141                	add	sp,sp,-16
    8000461e:	e406                	sd	ra,8(sp)
    80004620:	e022                	sd	s0,0(sp)
    80004622:	0800                	add	s0,sp,16
    80004624:	862e                	mv	a2,a1
  return namex(path, 1, name);
    80004626:	4585                	li	a1,1
    80004628:	f21ff0ef          	jal	80004548 <namex>
}
    8000462c:	60a2                	ld	ra,8(sp)
    8000462e:	6402                	ld	s0,0(sp)
    80004630:	0141                	add	sp,sp,16
    80004632:	8082                	ret

0000000080004634 <initsleeplock>:
#include "../proc/proc.h"


void
initsleeplock(struct sleeplock *lk, char *name)
{
    80004634:	1101                	add	sp,sp,-32
    80004636:	ec06                	sd	ra,24(sp)
    80004638:	e822                	sd	s0,16(sp)
    8000463a:	e426                	sd	s1,8(sp)
    8000463c:	e04a                	sd	s2,0(sp)
    8000463e:	1000                	add	s0,sp,32
    80004640:	84aa                	mv	s1,a0
    80004642:	892e                	mv	s2,a1
  initlock(&lk->lk, "sleep lock");
    80004644:	00002597          	auipc	a1,0x2
    80004648:	dcc58593          	add	a1,a1,-564 # 80006410 <syscalls+0x460>
    8000464c:	0521                	add	a0,a0,8
    8000464e:	9b7fd0ef          	jal	80002004 <initlock>
  lk->name = name;
    80004652:	0324b023          	sd	s2,32(s1)
  lk->locked = 0;
    80004656:	0004a023          	sw	zero,0(s1)
  lk->pid = 0;
    8000465a:	0204a423          	sw	zero,40(s1)
}
    8000465e:	60e2                	ld	ra,24(sp)
    80004660:	6442                	ld	s0,16(sp)
    80004662:	64a2                	ld	s1,8(sp)
    80004664:	6902                	ld	s2,0(sp)
    80004666:	6105                	add	sp,sp,32
    80004668:	8082                	ret

000000008000466a <acquiresleep>:

void
acquiresleep(struct sleeplock *lk)
{
    8000466a:	1101                	add	sp,sp,-32
    8000466c:	ec06                	sd	ra,24(sp)
    8000466e:	e822                	sd	s0,16(sp)
    80004670:	e426                	sd	s1,8(sp)
    80004672:	e04a                	sd	s2,0(sp)
    80004674:	1000                	add	s0,sp,32
    80004676:	84aa                	mv	s1,a0
  acquire(&lk->lk);
    80004678:	00850913          	add	s2,a0,8
    8000467c:	854a                	mv	a0,s2
    8000467e:	9e9fd0ef          	jal	80002066 <acquire>
  while (lk->locked) {
    80004682:	409c                	lw	a5,0(s1)
    80004684:	c799                	beqz	a5,80004692 <acquiresleep+0x28>
    sleep(lk, &lk->lk);
    80004686:	85ca                	mv	a1,s2
    80004688:	8526                	mv	a0,s1
    8000468a:	908fe0ef          	jal	80002792 <sleep>
  while (lk->locked) {
    8000468e:	409c                	lw	a5,0(s1)
    80004690:	fbfd                	bnez	a5,80004686 <acquiresleep+0x1c>
  }
  lk->locked = 1;
    80004692:	4785                	li	a5,1
    80004694:	c09c                	sw	a5,0(s1)
  lk->pid = myproc()->pid;
    80004696:	ecdfd0ef          	jal	80002562 <myproc>
    8000469a:	591c                	lw	a5,48(a0)
    8000469c:	d49c                	sw	a5,40(s1)
  release(&lk->lk);
    8000469e:	854a                	mv	a0,s2
    800046a0:	a6dfd0ef          	jal	8000210c <release>
}
    800046a4:	60e2                	ld	ra,24(sp)
    800046a6:	6442                	ld	s0,16(sp)
    800046a8:	64a2                	ld	s1,8(sp)
    800046aa:	6902                	ld	s2,0(sp)
    800046ac:	6105                	add	sp,sp,32
    800046ae:	8082                	ret

00000000800046b0 <releasesleep>:

void
releasesleep(struct sleeplock *lk)
{
    800046b0:	1101                	add	sp,sp,-32
    800046b2:	ec06                	sd	ra,24(sp)
    800046b4:	e822                	sd	s0,16(sp)
    800046b6:	e426                	sd	s1,8(sp)
    800046b8:	e04a                	sd	s2,0(sp)
    800046ba:	1000                	add	s0,sp,32
    800046bc:	84aa                	mv	s1,a0
  acquire(&lk->lk);
    800046be:	00850913          	add	s2,a0,8
    800046c2:	854a                	mv	a0,s2
    800046c4:	9a3fd0ef          	jal	80002066 <acquire>
  lk->locked = 0;
    800046c8:	0004a023          	sw	zero,0(s1)
  lk->pid = 0;
    800046cc:	0204a423          	sw	zero,40(s1)
  wakeup(lk);
    800046d0:	8526                	mv	a0,s1
    800046d2:	f73fd0ef          	jal	80002644 <wakeup>
  release(&lk->lk);
    800046d6:	854a                	mv	a0,s2
    800046d8:	a35fd0ef          	jal	8000210c <release>
}
    800046dc:	60e2                	ld	ra,24(sp)
    800046de:	6442                	ld	s0,16(sp)
    800046e0:	64a2                	ld	s1,8(sp)
    800046e2:	6902                	ld	s2,0(sp)
    800046e4:	6105                	add	sp,sp,32
    800046e6:	8082                	ret

00000000800046e8 <holdingsleep>:

int
holdingsleep(struct sleeplock *lk)
{
    800046e8:	7179                	add	sp,sp,-48
    800046ea:	f406                	sd	ra,40(sp)
    800046ec:	f022                	sd	s0,32(sp)
    800046ee:	ec26                	sd	s1,24(sp)
    800046f0:	e84a                	sd	s2,16(sp)
    800046f2:	e44e                	sd	s3,8(sp)
    800046f4:	1800                	add	s0,sp,48
    800046f6:	84aa                	mv	s1,a0
  int r;
  
  acquire(&lk->lk);
    800046f8:	00850913          	add	s2,a0,8
    800046fc:	854a                	mv	a0,s2
    800046fe:	969fd0ef          	jal	80002066 <acquire>
  r = lk->locked && (lk->pid == myproc()->pid);
    80004702:	409c                	lw	a5,0(s1)
    80004704:	ef89                	bnez	a5,8000471e <holdingsleep+0x36>
    80004706:	4481                	li	s1,0
  release(&lk->lk);
    80004708:	854a                	mv	a0,s2
    8000470a:	a03fd0ef          	jal	8000210c <release>
  return r;
}
    8000470e:	8526                	mv	a0,s1
    80004710:	70a2                	ld	ra,40(sp)
    80004712:	7402                	ld	s0,32(sp)
    80004714:	64e2                	ld	s1,24(sp)
    80004716:	6942                	ld	s2,16(sp)
    80004718:	69a2                	ld	s3,8(sp)
    8000471a:	6145                	add	sp,sp,48
    8000471c:	8082                	ret
  r = lk->locked && (lk->pid == myproc()->pid);
    8000471e:	0284a983          	lw	s3,40(s1)
    80004722:	e41fd0ef          	jal	80002562 <myproc>
    80004726:	5904                	lw	s1,48(a0)
    80004728:	413484b3          	sub	s1,s1,s3
    8000472c:	0014b493          	seqz	s1,s1
    80004730:	bfe1                	j	80004708 <holdingsleep+0x20>

0000000080004732 <virtio_disk_init>:

struct virtio_disk disk;

void
virtio_disk_init(void)
{
    80004732:	1101                	add	sp,sp,-32
    80004734:	ec06                	sd	ra,24(sp)
    80004736:	e822                	sd	s0,16(sp)
    80004738:	e426                	sd	s1,8(sp)
    8000473a:	e04a                	sd	s2,0(sp)
    8000473c:	1000                	add	s0,sp,32
  uint32 status = 0;

  initlock(&disk.vdisk_lock, "virtio_disk");
    8000473e:	00002597          	auipc	a1,0x2
    80004742:	ce258593          	add	a1,a1,-798 # 80006420 <syscalls+0x470>
    80004746:	00013517          	auipc	a0,0x13
    8000474a:	e5250513          	add	a0,a0,-430 # 80017598 <disk+0x128>
    8000474e:	8b7fd0ef          	jal	80002004 <initlock>

  if(*R(VIRTIO_MMIO_MAGIC_VALUE) != 0x74726976 ||
    80004752:	100017b7          	lui	a5,0x10001
    80004756:	4398                	lw	a4,0(a5)
    80004758:	2701                	sext.w	a4,a4
    8000475a:	747277b7          	lui	a5,0x74727
    8000475e:	97678793          	add	a5,a5,-1674 # 74726976 <_entry-0xb8d968a>
    80004762:	00f71963          	bne	a4,a5,80004774 <virtio_disk_init+0x42>
     *R(VIRTIO_MMIO_VERSION) != 2 ||
    80004766:	100017b7          	lui	a5,0x10001
    8000476a:	43dc                	lw	a5,4(a5)
    8000476c:	2781                	sext.w	a5,a5
  if(*R(VIRTIO_MMIO_MAGIC_VALUE) != 0x74726976 ||
    8000476e:	4709                	li	a4,2
    80004770:	12e78463          	beq	a5,a4,80004898 <virtio_disk_init+0x166>
     *R(VIRTIO_MMIO_DEVICE_ID) != 2 ||
     *R(VIRTIO_MMIO_VENDOR_ID) != 0x554d4551){
    panic("could not find virtio disk");
    80004774:	00002517          	auipc	a0,0x2
    80004778:	cbc50513          	add	a0,a0,-836 # 80006430 <syscalls+0x480>
    8000477c:	a24fc0ef          	jal	800009a0 <panic>
  }
  
  // reset device
  *R(VIRTIO_MMIO_STATUS) = status;
    80004780:	100017b7          	lui	a5,0x10001
    80004784:	0607a823          	sw	zero,112(a5) # 10001070 <_entry-0x6fffef90>

  // set ACKNOWLEDGE status bit
  status |= VIRTIO_CONFIG_S_ACKNOWLEDGE;
  *R(VIRTIO_MMIO_STATUS) = status;
    80004788:	4705                	li	a4,1
    8000478a:	dbb8                	sw	a4,112(a5)

  // set DRIVER status bit
  status |= VIRTIO_CONFIG_S_DRIVER;
  *R(VIRTIO_MMIO_STATUS) = status;
    8000478c:	470d                	li	a4,3
    8000478e:	dbb8                	sw	a4,112(a5)

  // negotiate features
  uint64 features = *R(VIRTIO_MMIO_DEVICE_FEATURES);
    80004790:	4b98                	lw	a4,16(a5)
  features &= ~(1 << VIRTIO_BLK_F_CONFIG_WCE);
  features &= ~(1 << VIRTIO_BLK_F_MQ);
  features &= ~(1 << VIRTIO_F_ANY_LAYOUT);
  features &= ~(1 << VIRTIO_RING_F_EVENT_IDX);
  features &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC);
  *R(VIRTIO_MMIO_DRIVER_FEATURES) = features;
    80004792:	c7ffe6b7          	lui	a3,0xc7ffe
    80004796:	75f68693          	add	a3,a3,1887 # ffffffffc7ffe75f <stack_top+0xffffffff47fe474f>
    8000479a:	8f75                	and	a4,a4,a3
    8000479c:	d398                	sw	a4,32(a5)

  // tell device that feature negotiation is complete.
  status |= VIRTIO_CONFIG_S_FEATURES_OK;
  *R(VIRTIO_MMIO_STATUS) = status;
    8000479e:	472d                	li	a4,11
    800047a0:	dbb8                	sw	a4,112(a5)

  // re-read status to ensure FEATURES_OK is set.
  status = *R(VIRTIO_MMIO_STATUS);
    800047a2:	5bbc                	lw	a5,112(a5)
    800047a4:	0007891b          	sext.w	s2,a5
  if(!(status & VIRTIO_CONFIG_S_FEATURES_OK))
    800047a8:	8ba1                	and	a5,a5,8
    800047aa:	10078863          	beqz	a5,800048ba <virtio_disk_init+0x188>
    panic("virtio disk FEATURES_OK unset");

  // initialize queue 0.
  *R(VIRTIO_MMIO_QUEUE_SEL) = 0;
    800047ae:	100017b7          	lui	a5,0x10001
    800047b2:	0207a823          	sw	zero,48(a5) # 10001030 <_entry-0x6fffefd0>

  // ensure queue 0 is not in use.
  if(*R(VIRTIO_MMIO_QUEUE_READY))
    800047b6:	43fc                	lw	a5,68(a5)
    800047b8:	2781                	sext.w	a5,a5
    800047ba:	10079763          	bnez	a5,800048c8 <virtio_disk_init+0x196>
    panic("virtio disk should not be ready");

  // check maximum queue size.
  uint32 max = *R(VIRTIO_MMIO_QUEUE_NUM_MAX);
    800047be:	100017b7          	lui	a5,0x10001
    800047c2:	5bdc                	lw	a5,52(a5)
    800047c4:	2781                	sext.w	a5,a5
  if(max == 0)
    800047c6:	10078863          	beqz	a5,800048d6 <virtio_disk_init+0x1a4>
    panic("virtio disk has no queue 0");
  if(max < NUM)
    800047ca:	471d                	li	a4,7
    800047cc:	10f77b63          	bgeu	a4,a5,800048e2 <virtio_disk_init+0x1b0>
    panic("virtio disk max queue too short");

  // allocate and zero queue memory.
  disk.desc = kalloc();
    800047d0:	5ef000ef          	jal	800055be <kalloc>
    800047d4:	00013497          	auipc	s1,0x13
    800047d8:	c9c48493          	add	s1,s1,-868 # 80017470 <disk>
    800047dc:	e088                	sd	a0,0(s1)
  disk.avail = kalloc();
    800047de:	5e1000ef          	jal	800055be <kalloc>
    800047e2:	e488                	sd	a0,8(s1)
  disk.used = kalloc();
    800047e4:	5db000ef          	jal	800055be <kalloc>
    800047e8:	e888                	sd	a0,16(s1)
  if(!disk.desc || !disk.avail || !disk.used)
    800047ea:	609c                	ld	a5,0(s1)
    800047ec:	c799                	beqz	a5,800047fa <virtio_disk_init+0xc8>
    800047ee:	00013797          	auipc	a5,0x13
    800047f2:	c8a7b783          	ld	a5,-886(a5) # 80017478 <disk+0x8>
    800047f6:	c391                	beqz	a5,800047fa <virtio_disk_init+0xc8>
    800047f8:	e519                	bnez	a0,80004806 <virtio_disk_init+0xd4>
    panic("virtio disk kalloc");
    800047fa:	00002517          	auipc	a0,0x2
    800047fe:	cd650513          	add	a0,a0,-810 # 800064d0 <syscalls+0x520>
    80004802:	99efc0ef          	jal	800009a0 <panic>
  memset(disk.desc, 0, PGSIZE);
    80004806:	00013497          	auipc	s1,0x13
    8000480a:	c6a48493          	add	s1,s1,-918 # 80017470 <disk>
    8000480e:	6605                	lui	a2,0x1
    80004810:	4581                	li	a1,0
    80004812:	6088                	ld	a0,0(s1)
    80004814:	327000ef          	jal	8000533a <memset>
  memset(disk.avail, 0, PGSIZE);
    80004818:	6605                	lui	a2,0x1
    8000481a:	4581                	li	a1,0
    8000481c:	6488                	ld	a0,8(s1)
    8000481e:	31d000ef          	jal	8000533a <memset>
  memset(disk.used, 0, PGSIZE);
    80004822:	6605                	lui	a2,0x1
    80004824:	4581                	li	a1,0
    80004826:	6888                	ld	a0,16(s1)
    80004828:	313000ef          	jal	8000533a <memset>

  // set queue size.
  *R(VIRTIO_MMIO_QUEUE_NUM) = NUM;
    8000482c:	100017b7          	lui	a5,0x10001
    80004830:	4721                	li	a4,8
    80004832:	df98                	sw	a4,56(a5)

  // write physical addresses.
  *R(VIRTIO_MMIO_QUEUE_DESC_LOW) = (uint64)disk.desc;
    80004834:	4098                	lw	a4,0(s1)
    80004836:	08e7a023          	sw	a4,128(a5) # 10001080 <_entry-0x6fffef80>
  *R(VIRTIO_MMIO_QUEUE_DESC_HIGH) = (uint64)disk.desc >> 32;
    8000483a:	40d8                	lw	a4,4(s1)
    8000483c:	08e7a223          	sw	a4,132(a5)
  *R(VIRTIO_MMIO_DRIVER_DESC_LOW) = (uint64)disk.avail;
    80004840:	6498                	ld	a4,8(s1)
    80004842:	0007069b          	sext.w	a3,a4
    80004846:	08d7a823          	sw	a3,144(a5)
  *R(VIRTIO_MMIO_DRIVER_DESC_HIGH) = (uint64)disk.avail >> 32;
    8000484a:	9701                	sra	a4,a4,0x20
    8000484c:	08e7aa23          	sw	a4,148(a5)
  *R(VIRTIO_MMIO_DEVICE_DESC_LOW) = (uint64)disk.used;
    80004850:	6898                	ld	a4,16(s1)
    80004852:	0007069b          	sext.w	a3,a4
    80004856:	0ad7a023          	sw	a3,160(a5)
  *R(VIRTIO_MMIO_DEVICE_DESC_HIGH) = (uint64)disk.used >> 32;
    8000485a:	9701                	sra	a4,a4,0x20
    8000485c:	0ae7a223          	sw	a4,164(a5)

  // queue is ready.
  *R(VIRTIO_MMIO_QUEUE_READY) = 0x1;
    80004860:	4705                	li	a4,1
    80004862:	c3f8                	sw	a4,68(a5)

  // all NUM descriptors start out unused.
  for(int i = 0; i < NUM; i++)
    disk.free[i] = 1;
    80004864:	00e48c23          	sb	a4,24(s1)
    80004868:	00e48ca3          	sb	a4,25(s1)
    8000486c:	00e48d23          	sb	a4,26(s1)
    80004870:	00e48da3          	sb	a4,27(s1)
    80004874:	00e48e23          	sb	a4,28(s1)
    80004878:	00e48ea3          	sb	a4,29(s1)
    8000487c:	00e48f23          	sb	a4,30(s1)
    80004880:	00e48fa3          	sb	a4,31(s1)

  // tell device we're completely ready.
  status |= VIRTIO_CONFIG_S_DRIVER_OK;
    80004884:	00496913          	or	s2,s2,4
  *R(VIRTIO_MMIO_STATUS) = status;
    80004888:	0727a823          	sw	s2,112(a5)

  // plic.c and trap.c arrange for interrupts from VIRTIO0_IRQ.
}
    8000488c:	60e2                	ld	ra,24(sp)
    8000488e:	6442                	ld	s0,16(sp)
    80004890:	64a2                	ld	s1,8(sp)
    80004892:	6902                	ld	s2,0(sp)
    80004894:	6105                	add	sp,sp,32
    80004896:	8082                	ret
     *R(VIRTIO_MMIO_DEVICE_ID) != 2 ||
    80004898:	100017b7          	lui	a5,0x10001
    8000489c:	479c                	lw	a5,8(a5)
    8000489e:	2781                	sext.w	a5,a5
     *R(VIRTIO_MMIO_VERSION) != 2 ||
    800048a0:	ece79ae3          	bne	a5,a4,80004774 <virtio_disk_init+0x42>
     *R(VIRTIO_MMIO_VENDOR_ID) != 0x554d4551){
    800048a4:	100017b7          	lui	a5,0x10001
    800048a8:	47d8                	lw	a4,12(a5)
    800048aa:	2701                	sext.w	a4,a4
     *R(VIRTIO_MMIO_DEVICE_ID) != 2 ||
    800048ac:	554d47b7          	lui	a5,0x554d4
    800048b0:	55178793          	add	a5,a5,1361 # 554d4551 <_entry-0x2ab2baaf>
    800048b4:	ecf710e3          	bne	a4,a5,80004774 <virtio_disk_init+0x42>
    800048b8:	b5e1                	j	80004780 <virtio_disk_init+0x4e>
    panic("virtio disk FEATURES_OK unset");
    800048ba:	00002517          	auipc	a0,0x2
    800048be:	b9650513          	add	a0,a0,-1130 # 80006450 <syscalls+0x4a0>
    800048c2:	8defc0ef          	jal	800009a0 <panic>
    800048c6:	b5e5                	j	800047ae <virtio_disk_init+0x7c>
    panic("virtio disk should not be ready");
    800048c8:	00002517          	auipc	a0,0x2
    800048cc:	ba850513          	add	a0,a0,-1112 # 80006470 <syscalls+0x4c0>
    800048d0:	8d0fc0ef          	jal	800009a0 <panic>
    800048d4:	b5ed                	j	800047be <virtio_disk_init+0x8c>
    panic("virtio disk has no queue 0");
    800048d6:	00002517          	auipc	a0,0x2
    800048da:	bba50513          	add	a0,a0,-1094 # 80006490 <syscalls+0x4e0>
    800048de:	8c2fc0ef          	jal	800009a0 <panic>
    panic("virtio disk max queue too short");
    800048e2:	00002517          	auipc	a0,0x2
    800048e6:	bce50513          	add	a0,a0,-1074 # 800064b0 <syscalls+0x500>
    800048ea:	8b6fc0ef          	jal	800009a0 <panic>
    800048ee:	b5cd                	j	800047d0 <virtio_disk_init+0x9e>

00000000800048f0 <alloc_desc>:

// find a free descriptor, mark it non-free, return its index.
 int
alloc_desc()
{
    800048f0:	1141                	add	sp,sp,-16
    800048f2:	e422                	sd	s0,8(sp)
    800048f4:	0800                	add	s0,sp,16
  for(int i = 0; i < NUM; i++){
    800048f6:	00013797          	auipc	a5,0x13
    800048fa:	b7a78793          	add	a5,a5,-1158 # 80017470 <disk>
    800048fe:	4501                	li	a0,0
    80004900:	46a1                	li	a3,8
    if(disk.free[i]){
    80004902:	0187c703          	lbu	a4,24(a5)
    80004906:	eb09                	bnez	a4,80004918 <alloc_desc+0x28>
  for(int i = 0; i < NUM; i++){
    80004908:	2505                	addw	a0,a0,1
    8000490a:	0785                	add	a5,a5,1
    8000490c:	fed51be3          	bne	a0,a3,80004902 <alloc_desc+0x12>
      disk.free[i] = 0;
      return i;
    }
  }
  return -1;
    80004910:	557d                	li	a0,-1
}
    80004912:	6422                	ld	s0,8(sp)
    80004914:	0141                	add	sp,sp,16
    80004916:	8082                	ret
      disk.free[i] = 0;
    80004918:	00013797          	auipc	a5,0x13
    8000491c:	b5878793          	add	a5,a5,-1192 # 80017470 <disk>
    80004920:	97aa                	add	a5,a5,a0
    80004922:	00078c23          	sb	zero,24(a5)
      return i;
    80004926:	b7f5                	j	80004912 <alloc_desc+0x22>

0000000080004928 <free_desc>:

// mark a descriptor as free.
 void
free_desc(int i)
{
    80004928:	1101                	add	sp,sp,-32
    8000492a:	ec06                	sd	ra,24(sp)
    8000492c:	e822                	sd	s0,16(sp)
    8000492e:	e426                	sd	s1,8(sp)
    80004930:	1000                	add	s0,sp,32
    80004932:	84aa                	mv	s1,a0
  if(i >= NUM)
    80004934:	479d                	li	a5,7
    80004936:	04a7cb63          	blt	a5,a0,8000498c <free_desc+0x64>
    panic("free_desc 1");
  if(disk.free[i])
    8000493a:	00013797          	auipc	a5,0x13
    8000493e:	b3678793          	add	a5,a5,-1226 # 80017470 <disk>
    80004942:	97a6                	add	a5,a5,s1
    80004944:	0187c783          	lbu	a5,24(a5)
    80004948:	eba9                	bnez	a5,8000499a <free_desc+0x72>
    panic("free_desc 2");
  disk.desc[i].addr = 0;
    8000494a:	00449693          	sll	a3,s1,0x4
    8000494e:	00013797          	auipc	a5,0x13
    80004952:	b2278793          	add	a5,a5,-1246 # 80017470 <disk>
    80004956:	6398                	ld	a4,0(a5)
    80004958:	9736                	add	a4,a4,a3
    8000495a:	00073023          	sd	zero,0(a4) # 43000 <_entry-0x7ffbd000>
  disk.desc[i].len = 0;
    8000495e:	6398                	ld	a4,0(a5)
    80004960:	9736                	add	a4,a4,a3
    80004962:	00072423          	sw	zero,8(a4)
  disk.desc[i].flags = 0;
    80004966:	00071623          	sh	zero,12(a4)
  disk.desc[i].next = 0;
    8000496a:	00071723          	sh	zero,14(a4)
  disk.free[i] = 1;
    8000496e:	97a6                	add	a5,a5,s1
    80004970:	4705                	li	a4,1
    80004972:	00e78c23          	sb	a4,24(a5)
  wakeup(&disk.free[0]);
    80004976:	00013517          	auipc	a0,0x13
    8000497a:	b1250513          	add	a0,a0,-1262 # 80017488 <disk+0x18>
    8000497e:	cc7fd0ef          	jal	80002644 <wakeup>
}
    80004982:	60e2                	ld	ra,24(sp)
    80004984:	6442                	ld	s0,16(sp)
    80004986:	64a2                	ld	s1,8(sp)
    80004988:	6105                	add	sp,sp,32
    8000498a:	8082                	ret
    panic("free_desc 1");
    8000498c:	00002517          	auipc	a0,0x2
    80004990:	b5c50513          	add	a0,a0,-1188 # 800064e8 <syscalls+0x538>
    80004994:	80cfc0ef          	jal	800009a0 <panic>
    80004998:	b74d                	j	8000493a <free_desc+0x12>
    panic("free_desc 2");
    8000499a:	00002517          	auipc	a0,0x2
    8000499e:	b5e50513          	add	a0,a0,-1186 # 800064f8 <syscalls+0x548>
    800049a2:	ffffb0ef          	jal	800009a0 <panic>
    800049a6:	b755                	j	8000494a <free_desc+0x22>

00000000800049a8 <free_chain>:

// free a chain of descriptors.
 void
free_chain(int i)
{
    800049a8:	7179                	add	sp,sp,-48
    800049aa:	f406                	sd	ra,40(sp)
    800049ac:	f022                	sd	s0,32(sp)
    800049ae:	ec26                	sd	s1,24(sp)
    800049b0:	e84a                	sd	s2,16(sp)
    800049b2:	e44e                	sd	s3,8(sp)
    800049b4:	1800                	add	s0,sp,48
    800049b6:	892a                	mv	s2,a0
  while(1){
    int flag = disk.desc[i].flags;
    800049b8:	00013997          	auipc	s3,0x13
    800049bc:	ab898993          	add	s3,s3,-1352 # 80017470 <disk>
    800049c0:	00491713          	sll	a4,s2,0x4
    800049c4:	0009b783          	ld	a5,0(s3)
    800049c8:	97ba                	add	a5,a5,a4
    800049ca:	00c7d483          	lhu	s1,12(a5)
    int nxt = disk.desc[i].next;
    800049ce:	854a                	mv	a0,s2
    800049d0:	00e7d903          	lhu	s2,14(a5)
    free_desc(i);
    800049d4:	f55ff0ef          	jal	80004928 <free_desc>
    if(flag & VRING_DESC_F_NEXT)
    800049d8:	8885                	and	s1,s1,1
    800049da:	f0fd                	bnez	s1,800049c0 <free_chain+0x18>
      i = nxt;
    else
      break;
  }
}
    800049dc:	70a2                	ld	ra,40(sp)
    800049de:	7402                	ld	s0,32(sp)
    800049e0:	64e2                	ld	s1,24(sp)
    800049e2:	6942                	ld	s2,16(sp)
    800049e4:	69a2                	ld	s3,8(sp)
    800049e6:	6145                	add	sp,sp,48
    800049e8:	8082                	ret

00000000800049ea <alloc3_desc>:

// allocate three descriptors (they need not be contiguous).
// disk transfers always use three descriptors.
 int
alloc3_desc(int *idx)
{
    800049ea:	7179                	add	sp,sp,-48
    800049ec:	f406                	sd	ra,40(sp)
    800049ee:	f022                	sd	s0,32(sp)
    800049f0:	ec26                	sd	s1,24(sp)
    800049f2:	e84a                	sd	s2,16(sp)
    800049f4:	e44e                	sd	s3,8(sp)
    800049f6:	e052                	sd	s4,0(sp)
    800049f8:	1800                	add	s0,sp,48
    800049fa:	89aa                	mv	s3,a0
    800049fc:	892a                	mv	s2,a0
  for(int i = 0; i < 3; i++){
    800049fe:	4481                	li	s1,0
    80004a00:	4a0d                	li	s4,3
    idx[i] = alloc_desc();
    80004a02:	eefff0ef          	jal	800048f0 <alloc_desc>
    80004a06:	00a92023          	sw	a0,0(s2)
    if(idx[i] < 0){
    80004a0a:	00054f63          	bltz	a0,80004a28 <alloc3_desc+0x3e>
  for(int i = 0; i < 3; i++){
    80004a0e:	2485                	addw	s1,s1,1
    80004a10:	0911                	add	s2,s2,4
    80004a12:	ff4498e3          	bne	s1,s4,80004a02 <alloc3_desc+0x18>
      for(int j = 0; j < i; j++)
        free_desc(idx[j]);
      return -1;
    }
  }
  return 0;
    80004a16:	4501                	li	a0,0
}
    80004a18:	70a2                	ld	ra,40(sp)
    80004a1a:	7402                	ld	s0,32(sp)
    80004a1c:	64e2                	ld	s1,24(sp)
    80004a1e:	6942                	ld	s2,16(sp)
    80004a20:	69a2                	ld	s3,8(sp)
    80004a22:	6a02                	ld	s4,0(sp)
    80004a24:	6145                	add	sp,sp,48
    80004a26:	8082                	ret
      return -1;
    80004a28:	557d                	li	a0,-1
      for(int j = 0; j < i; j++)
    80004a2a:	fe9057e3          	blez	s1,80004a18 <alloc3_desc+0x2e>
    80004a2e:	048a                	sll	s1,s1,0x2
    80004a30:	94ce                	add	s1,s1,s3
        free_desc(idx[j]);
    80004a32:	0009a503          	lw	a0,0(s3)
    80004a36:	ef3ff0ef          	jal	80004928 <free_desc>
      for(int j = 0; j < i; j++)
    80004a3a:	0991                	add	s3,s3,4
    80004a3c:	fe999be3          	bne	s3,s1,80004a32 <alloc3_desc+0x48>
      return -1;
    80004a40:	557d                	li	a0,-1
    80004a42:	bfd9                	j	80004a18 <alloc3_desc+0x2e>

0000000080004a44 <virtio_disk_rw>:

void
virtio_disk_rw(struct buf *b, int write)
{
    80004a44:	715d                	add	sp,sp,-80
    80004a46:	e486                	sd	ra,72(sp)
    80004a48:	e0a2                	sd	s0,64(sp)
    80004a4a:	fc26                	sd	s1,56(sp)
    80004a4c:	f84a                	sd	s2,48(sp)
    80004a4e:	f44e                	sd	s3,40(sp)
    80004a50:	f052                	sd	s4,32(sp)
    80004a52:	ec56                	sd	s5,24(sp)
    80004a54:	0880                	add	s0,sp,80
    80004a56:	84aa                	mv	s1,a0
    80004a58:	8a2e                	mv	s4,a1
  uint64 sector = b->blockno * (BSIZE / 512);
    80004a5a:	00c52a83          	lw	s5,12(a0)
    80004a5e:	001a9a9b          	sllw	s5,s5,0x1
    80004a62:	1a82                	sll	s5,s5,0x20
    80004a64:	020ada93          	srl	s5,s5,0x20

  acquire(&disk.vdisk_lock);
    80004a68:	00013517          	auipc	a0,0x13
    80004a6c:	b3050513          	add	a0,a0,-1232 # 80017598 <disk+0x128>
    80004a70:	df6fd0ef          	jal	80002066 <acquire>
  int idx[3];
  while(1){
    if(alloc3_desc(idx) == 0) {
      break;
    }
    sleep(&disk.free[0], &disk.vdisk_lock);
    80004a74:	00013997          	auipc	s3,0x13
    80004a78:	b2498993          	add	s3,s3,-1244 # 80017598 <disk+0x128>
    80004a7c:	00013917          	auipc	s2,0x13
    80004a80:	a0c90913          	add	s2,s2,-1524 # 80017488 <disk+0x18>
    80004a84:	a029                	j	80004a8e <virtio_disk_rw+0x4a>
    80004a86:	85ce                	mv	a1,s3
    80004a88:	854a                	mv	a0,s2
    80004a8a:	d09fd0ef          	jal	80002792 <sleep>
    if(alloc3_desc(idx) == 0) {
    80004a8e:	fb040513          	add	a0,s0,-80
    80004a92:	f59ff0ef          	jal	800049ea <alloc3_desc>
    80004a96:	f965                	bnez	a0,80004a86 <virtio_disk_rw+0x42>
  }

  // format the three descriptors.
  // qemu's virtio-blk.c reads them.

  struct virtio_blk_req *buf0 = &disk.ops[idx[0]];
    80004a98:	fb042503          	lw	a0,-80(s0)
    80004a9c:	00a50713          	add	a4,a0,10
    80004aa0:	0712                	sll	a4,a4,0x4

  if(write)
    80004aa2:	00013797          	auipc	a5,0x13
    80004aa6:	9ce78793          	add	a5,a5,-1586 # 80017470 <disk>
    80004aaa:	00e786b3          	add	a3,a5,a4
    80004aae:	01403633          	snez	a2,s4
    80004ab2:	c690                	sw	a2,8(a3)
    buf0->type = VIRTIO_BLK_T_OUT; // write the disk
  else
    buf0->type = VIRTIO_BLK_T_IN; // read the disk
  buf0->reserved = 0;
    80004ab4:	0006a623          	sw	zero,12(a3)
  buf0->sector = sector;
    80004ab8:	0156b823          	sd	s5,16(a3)

  disk.desc[idx[0]].addr = (uint64) buf0;
    80004abc:	f6070613          	add	a2,a4,-160
    80004ac0:	6394                	ld	a3,0(a5)
    80004ac2:	96b2                	add	a3,a3,a2
  struct virtio_blk_req *buf0 = &disk.ops[idx[0]];
    80004ac4:	00870593          	add	a1,a4,8
    80004ac8:	95be                	add	a1,a1,a5
  disk.desc[idx[0]].addr = (uint64) buf0;
    80004aca:	e28c                	sd	a1,0(a3)
  disk.desc[idx[0]].len = sizeof(struct virtio_blk_req);
    80004acc:	0007b803          	ld	a6,0(a5)
    80004ad0:	9642                	add	a2,a2,a6
    80004ad2:	46c1                	li	a3,16
    80004ad4:	c614                	sw	a3,8(a2)
  disk.desc[idx[0]].flags = VRING_DESC_F_NEXT;
    80004ad6:	4585                	li	a1,1
    80004ad8:	00b61623          	sh	a1,12(a2) # 100c <_entry-0x7fffeff4>
  disk.desc[idx[0]].next = idx[1];
    80004adc:	fb442683          	lw	a3,-76(s0)
    80004ae0:	00d61723          	sh	a3,14(a2)

  disk.desc[idx[1]].addr = (uint64) b->data;
    80004ae4:	0692                	sll	a3,a3,0x4
    80004ae6:	9836                	add	a6,a6,a3
    80004ae8:	05848613          	add	a2,s1,88
    80004aec:	00c83023          	sd	a2,0(a6)
  disk.desc[idx[1]].len = BSIZE;
    80004af0:	0007b803          	ld	a6,0(a5)
    80004af4:	96c2                	add	a3,a3,a6
    80004af6:	40000613          	li	a2,1024
    80004afa:	c690                	sw	a2,8(a3)
  if(write)
    80004afc:	001a3a13          	seqz	s4,s4
    80004b00:	001a1a1b          	sllw	s4,s4,0x1
    disk.desc[idx[1]].flags = 0; // device reads b->data
  else
    disk.desc[idx[1]].flags = VRING_DESC_F_WRITE; // device writes b->data
  disk.desc[idx[1]].flags |= VRING_DESC_F_NEXT;
    80004b04:	001a6a13          	or	s4,s4,1
    80004b08:	01469623          	sh	s4,12(a3)
  disk.desc[idx[1]].next = idx[2];
    80004b0c:	fb842603          	lw	a2,-72(s0)
    80004b10:	00c69723          	sh	a2,14(a3)

  disk.info[idx[0]].status = 0xff; // device writes 0 on success
    80004b14:	00250693          	add	a3,a0,2
    80004b18:	0692                	sll	a3,a3,0x4
    80004b1a:	96be                	add	a3,a3,a5
    80004b1c:	58fd                	li	a7,-1
    80004b1e:	01168823          	sb	a7,16(a3)
  disk.desc[idx[2]].addr = (uint64) &disk.info[idx[0]].status;
    80004b22:	0612                	sll	a2,a2,0x4
    80004b24:	9832                	add	a6,a6,a2
    80004b26:	f9070713          	add	a4,a4,-112
    80004b2a:	973e                	add	a4,a4,a5
    80004b2c:	00e83023          	sd	a4,0(a6)
  disk.desc[idx[2]].len = 1;
    80004b30:	6398                	ld	a4,0(a5)
    80004b32:	9732                	add	a4,a4,a2
    80004b34:	c70c                	sw	a1,8(a4)
  disk.desc[idx[2]].flags = VRING_DESC_F_WRITE; // device writes the status
    80004b36:	4609                	li	a2,2
    80004b38:	00c71623          	sh	a2,12(a4)
  disk.desc[idx[2]].next = 0;
    80004b3c:	00071723          	sh	zero,14(a4)

  // record struct buf for virtio_disk_intr().
  b->disk = 1;
    80004b40:	c0cc                	sw	a1,4(s1)
  disk.info[idx[0]].b = b;
    80004b42:	e684                	sd	s1,8(a3)

  // tell the device the first index in our chain of descriptors.
  disk.avail->ring[disk.avail->idx % NUM] = idx[0];
    80004b44:	6794                	ld	a3,8(a5)
    80004b46:	0026d703          	lhu	a4,2(a3)
    80004b4a:	8b1d                	and	a4,a4,7
    80004b4c:	0706                	sll	a4,a4,0x1
    80004b4e:	96ba                	add	a3,a3,a4
    80004b50:	00a69223          	sh	a0,4(a3)

  __sync_synchronize();
    80004b54:	0ff0000f          	fence

  // tell the device another avail ring entry is available.
  disk.avail->idx += 1; // not % NUM ...
    80004b58:	6798                	ld	a4,8(a5)
    80004b5a:	00275783          	lhu	a5,2(a4)
    80004b5e:	2785                	addw	a5,a5,1
    80004b60:	00f71123          	sh	a5,2(a4)

  __sync_synchronize();
    80004b64:	0ff0000f          	fence

  *R(VIRTIO_MMIO_QUEUE_NOTIFY) = 0; // value is queue number
    80004b68:	100017b7          	lui	a5,0x10001
    80004b6c:	0407a823          	sw	zero,80(a5) # 10001050 <_entry-0x6fffefb0>

  // Wait for virtio_disk_intr() to say request has finished.
  while(b->disk == 1) {
    80004b70:	40dc                	lw	a5,4(s1)
    80004b72:	00b79e63          	bne	a5,a1,80004b8e <virtio_disk_rw+0x14a>
    sleep(b, &disk.vdisk_lock);
    80004b76:	00013997          	auipc	s3,0x13
    80004b7a:	a2298993          	add	s3,s3,-1502 # 80017598 <disk+0x128>
  while(b->disk == 1) {
    80004b7e:	4905                	li	s2,1
    sleep(b, &disk.vdisk_lock);
    80004b80:	85ce                	mv	a1,s3
    80004b82:	8526                	mv	a0,s1
    80004b84:	c0ffd0ef          	jal	80002792 <sleep>
  while(b->disk == 1) {
    80004b88:	40dc                	lw	a5,4(s1)
    80004b8a:	ff278be3          	beq	a5,s2,80004b80 <virtio_disk_rw+0x13c>
  }

  disk.info[idx[0]].b = 0;
    80004b8e:	fb042503          	lw	a0,-80(s0)
    80004b92:	00250713          	add	a4,a0,2
    80004b96:	0712                	sll	a4,a4,0x4
    80004b98:	00013797          	auipc	a5,0x13
    80004b9c:	8d878793          	add	a5,a5,-1832 # 80017470 <disk>
    80004ba0:	97ba                	add	a5,a5,a4
    80004ba2:	0007b423          	sd	zero,8(a5)
  free_chain(idx[0]);
    80004ba6:	e03ff0ef          	jal	800049a8 <free_chain>

  release(&disk.vdisk_lock);
    80004baa:	00013517          	auipc	a0,0x13
    80004bae:	9ee50513          	add	a0,a0,-1554 # 80017598 <disk+0x128>
    80004bb2:	d5afd0ef          	jal	8000210c <release>
}
    80004bb6:	60a6                	ld	ra,72(sp)
    80004bb8:	6406                	ld	s0,64(sp)
    80004bba:	74e2                	ld	s1,56(sp)
    80004bbc:	7942                	ld	s2,48(sp)
    80004bbe:	79a2                	ld	s3,40(sp)
    80004bc0:	7a02                	ld	s4,32(sp)
    80004bc2:	6ae2                	ld	s5,24(sp)
    80004bc4:	6161                	add	sp,sp,80
    80004bc6:	8082                	ret

0000000080004bc8 <virtio_disk_intr>:

void
virtio_disk_intr()
{
    80004bc8:	7179                	add	sp,sp,-48
    80004bca:	f406                	sd	ra,40(sp)
    80004bcc:	f022                	sd	s0,32(sp)
    80004bce:	ec26                	sd	s1,24(sp)
    80004bd0:	e84a                	sd	s2,16(sp)
    80004bd2:	e44e                	sd	s3,8(sp)
    80004bd4:	1800                	add	s0,sp,48
  acquire(&disk.vdisk_lock);
    80004bd6:	00013497          	auipc	s1,0x13
    80004bda:	89a48493          	add	s1,s1,-1894 # 80017470 <disk>
    80004bde:	00013517          	auipc	a0,0x13
    80004be2:	9ba50513          	add	a0,a0,-1606 # 80017598 <disk+0x128>
    80004be6:	c80fd0ef          	jal	80002066 <acquire>
  // we've seen this interrupt, which the following line does.
  // this may race with the device writing new entries to
  // the "used" ring, in which case we may process the new
  // completion entries in this interrupt, and have nothing to do
  // in the next interrupt, which is harmless.
  *R(VIRTIO_MMIO_INTERRUPT_ACK) = *R(VIRTIO_MMIO_INTERRUPT_STATUS) & 0x3;
    80004bea:	10001737          	lui	a4,0x10001
    80004bee:	533c                	lw	a5,96(a4)
    80004bf0:	8b8d                	and	a5,a5,3
    80004bf2:	d37c                	sw	a5,100(a4)

  __sync_synchronize();
    80004bf4:	0ff0000f          	fence

  // the device increments disk.used->idx when it
  // adds an entry to the used ring.

  while(disk.used_idx != disk.used->idx){
    80004bf8:	689c                	ld	a5,16(s1)
    80004bfa:	0204d703          	lhu	a4,32(s1)
    80004bfe:	0027d783          	lhu	a5,2(a5)
    80004c02:	06f70263          	beq	a4,a5,80004c66 <virtio_disk_intr+0x9e>
    __sync_synchronize();
    int id = disk.used->ring[disk.used_idx % NUM].id;
    80004c06:	8926                	mv	s2,s1

    if(disk.info[id].status != 0)
      panic("virtio_disk_intr status");
    80004c08:	00002997          	auipc	s3,0x2
    80004c0c:	90098993          	add	s3,s3,-1792 # 80006508 <syscalls+0x558>
    80004c10:	a035                	j	80004c3c <virtio_disk_intr+0x74>

    struct buf *b = disk.info[id].b;
    80004c12:	0489                	add	s1,s1,2
    80004c14:	0492                	sll	s1,s1,0x4
    80004c16:	94ca                	add	s1,s1,s2
    80004c18:	6488                	ld	a0,8(s1)
    b->disk = 0;   // disk is done with buf
    80004c1a:	00052223          	sw	zero,4(a0)
    wakeup(b);
    80004c1e:	a27fd0ef          	jal	80002644 <wakeup>

    disk.used_idx += 1;
    80004c22:	02095783          	lhu	a5,32(s2)
    80004c26:	2785                	addw	a5,a5,1
    80004c28:	17c2                	sll	a5,a5,0x30
    80004c2a:	93c1                	srl	a5,a5,0x30
    80004c2c:	02f91023          	sh	a5,32(s2)
  while(disk.used_idx != disk.used->idx){
    80004c30:	01093703          	ld	a4,16(s2)
    80004c34:	00275703          	lhu	a4,2(a4) # 10001002 <_entry-0x6fffeffe>
    80004c38:	02f70763          	beq	a4,a5,80004c66 <virtio_disk_intr+0x9e>
    __sync_synchronize();
    80004c3c:	0ff0000f          	fence
    int id = disk.used->ring[disk.used_idx % NUM].id;
    80004c40:	01093703          	ld	a4,16(s2)
    80004c44:	02095783          	lhu	a5,32(s2)
    80004c48:	8b9d                	and	a5,a5,7
    80004c4a:	078e                	sll	a5,a5,0x3
    80004c4c:	97ba                	add	a5,a5,a4
    80004c4e:	43c4                	lw	s1,4(a5)
    if(disk.info[id].status != 0)
    80004c50:	00248793          	add	a5,s1,2
    80004c54:	0792                	sll	a5,a5,0x4
    80004c56:	97ca                	add	a5,a5,s2
    80004c58:	0107c783          	lbu	a5,16(a5)
    80004c5c:	dbdd                	beqz	a5,80004c12 <virtio_disk_intr+0x4a>
      panic("virtio_disk_intr status");
    80004c5e:	854e                	mv	a0,s3
    80004c60:	d41fb0ef          	jal	800009a0 <panic>
    80004c64:	b77d                	j	80004c12 <virtio_disk_intr+0x4a>
  }

  release(&disk.vdisk_lock);
    80004c66:	00013517          	auipc	a0,0x13
    80004c6a:	93250513          	add	a0,a0,-1742 # 80017598 <disk+0x128>
    80004c6e:	c9efd0ef          	jal	8000210c <release>
}
    80004c72:	70a2                	ld	ra,40(sp)
    80004c74:	7402                	ld	s0,32(sp)
    80004c76:	64e2                	ld	s1,24(sp)
    80004c78:	6942                	ld	s2,16(sp)
    80004c7a:	69a2                	ld	s3,8(sp)
    80004c7c:	6145                	add	sp,sp,48
    80004c7e:	8082                	ret

0000000080004c80 <pipealloc>:
#include "../proc/proc.h"
#include "../trap/syscall.h"

int
pipealloc(struct file **f0, struct file **f1)
{
    80004c80:	7179                	add	sp,sp,-48
    80004c82:	f406                	sd	ra,40(sp)
    80004c84:	f022                	sd	s0,32(sp)
    80004c86:	ec26                	sd	s1,24(sp)
    80004c88:	e84a                	sd	s2,16(sp)
    80004c8a:	e44e                	sd	s3,8(sp)
    80004c8c:	e052                	sd	s4,0(sp)
    80004c8e:	1800                	add	s0,sp,48
    80004c90:	84aa                	mv	s1,a0
    80004c92:	8a2e                	mv	s4,a1
  struct pipe *pi;

  pi = 0;
  *f0 = *f1 = 0;
    80004c94:	0005b023          	sd	zero,0(a1)
    80004c98:	00053023          	sd	zero,0(a0)
  if((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0)
    80004c9c:	8cbfe0ef          	jal	80003566 <filealloc>
    80004ca0:	e088                	sd	a0,0(s1)
    80004ca2:	cd35                	beqz	a0,80004d1e <pipealloc+0x9e>
    80004ca4:	8c3fe0ef          	jal	80003566 <filealloc>
    80004ca8:	00aa3023          	sd	a0,0(s4)
    80004cac:	c52d                	beqz	a0,80004d16 <pipealloc+0x96>
    goto bad;
  if((pi = (struct pipe*)kalloc()) == 0)
    80004cae:	111000ef          	jal	800055be <kalloc>
    80004cb2:	892a                	mv	s2,a0
    80004cb4:	cd31                	beqz	a0,80004d10 <pipealloc+0x90>
    goto bad;
  pi->readopen = 1;
    80004cb6:	4985                	li	s3,1
    80004cb8:	23352023          	sw	s3,544(a0)
  pi->writeopen = 1;
    80004cbc:	23352223          	sw	s3,548(a0)
  pi->nwrite = 0;
    80004cc0:	20052e23          	sw	zero,540(a0)
  pi->nread = 0;
    80004cc4:	20052c23          	sw	zero,536(a0)
  initlock(&pi->lock, "pipe");
    80004cc8:	00002597          	auipc	a1,0x2
    80004ccc:	85858593          	add	a1,a1,-1960 # 80006520 <syscalls+0x570>
    80004cd0:	b34fd0ef          	jal	80002004 <initlock>
  (*f0)->type = FD_PIPE;
    80004cd4:	609c                	ld	a5,0(s1)
    80004cd6:	0137a023          	sw	s3,0(a5)
  (*f0)->readable = 1;
    80004cda:	609c                	ld	a5,0(s1)
    80004cdc:	01378423          	sb	s3,8(a5)
  (*f0)->writable = 0;
    80004ce0:	609c                	ld	a5,0(s1)
    80004ce2:	000784a3          	sb	zero,9(a5)
  (*f0)->pipe = pi;
    80004ce6:	609c                	ld	a5,0(s1)
    80004ce8:	0127b823          	sd	s2,16(a5)
  (*f1)->type = FD_PIPE;
    80004cec:	000a3783          	ld	a5,0(s4)
    80004cf0:	0137a023          	sw	s3,0(a5)
  (*f1)->readable = 0;
    80004cf4:	000a3783          	ld	a5,0(s4)
    80004cf8:	00078423          	sb	zero,8(a5)
  (*f1)->writable = 1;
    80004cfc:	000a3783          	ld	a5,0(s4)
    80004d00:	013784a3          	sb	s3,9(a5)
  (*f1)->pipe = pi;
    80004d04:	000a3783          	ld	a5,0(s4)
    80004d08:	0127b823          	sd	s2,16(a5)
  return 0;
    80004d0c:	4501                	li	a0,0
    80004d0e:	a005                	j	80004d2e <pipealloc+0xae>

 bad:
  if(pi)
    kfree((char*)pi);
  if(*f0)
    80004d10:	6088                	ld	a0,0(s1)
    80004d12:	e501                	bnez	a0,80004d1a <pipealloc+0x9a>
    80004d14:	a029                	j	80004d1e <pipealloc+0x9e>
    80004d16:	6088                	ld	a0,0(s1)
    80004d18:	c11d                	beqz	a0,80004d3e <pipealloc+0xbe>
    fileclose(*f0);
    80004d1a:	8f5fe0ef          	jal	8000360e <fileclose>
  if(*f1)
    80004d1e:	000a3783          	ld	a5,0(s4)
    fileclose(*f1);
  return -1;
    80004d22:	557d                	li	a0,-1
  if(*f1)
    80004d24:	c789                	beqz	a5,80004d2e <pipealloc+0xae>
    fileclose(*f1);
    80004d26:	853e                	mv	a0,a5
    80004d28:	8e7fe0ef          	jal	8000360e <fileclose>
  return -1;
    80004d2c:	557d                	li	a0,-1
}
    80004d2e:	70a2                	ld	ra,40(sp)
    80004d30:	7402                	ld	s0,32(sp)
    80004d32:	64e2                	ld	s1,24(sp)
    80004d34:	6942                	ld	s2,16(sp)
    80004d36:	69a2                	ld	s3,8(sp)
    80004d38:	6a02                	ld	s4,0(sp)
    80004d3a:	6145                	add	sp,sp,48
    80004d3c:	8082                	ret
  return -1;
    80004d3e:	557d                	li	a0,-1
    80004d40:	b7fd                	j	80004d2e <pipealloc+0xae>

0000000080004d42 <pipeclose>:

void
pipeclose(struct pipe *pi, int writable)
{
    80004d42:	1101                	add	sp,sp,-32
    80004d44:	ec06                	sd	ra,24(sp)
    80004d46:	e822                	sd	s0,16(sp)
    80004d48:	e426                	sd	s1,8(sp)
    80004d4a:	e04a                	sd	s2,0(sp)
    80004d4c:	1000                	add	s0,sp,32
    80004d4e:	84aa                	mv	s1,a0
    80004d50:	892e                	mv	s2,a1
  acquire(&pi->lock);
    80004d52:	b14fd0ef          	jal	80002066 <acquire>
  if(writable){
    80004d56:	02090763          	beqz	s2,80004d84 <pipeclose+0x42>
    pi->writeopen = 0;
    80004d5a:	2204a223          	sw	zero,548(s1)
    wakeup(&pi->nread);
    80004d5e:	21848513          	add	a0,s1,536
    80004d62:	8e3fd0ef          	jal	80002644 <wakeup>
  } else {
    pi->readopen = 0;
    wakeup(&pi->nwrite);
  }
  if(pi->readopen == 0 && pi->writeopen == 0){
    80004d66:	2204b783          	ld	a5,544(s1)
    80004d6a:	e785                	bnez	a5,80004d92 <pipeclose+0x50>
    release(&pi->lock);
    80004d6c:	8526                	mv	a0,s1
    80004d6e:	b9efd0ef          	jal	8000210c <release>
    kfree((char*)pi);
    80004d72:	8526                	mv	a0,s1
    80004d74:	766000ef          	jal	800054da <kfree>
  } else
    release(&pi->lock);
}
    80004d78:	60e2                	ld	ra,24(sp)
    80004d7a:	6442                	ld	s0,16(sp)
    80004d7c:	64a2                	ld	s1,8(sp)
    80004d7e:	6902                	ld	s2,0(sp)
    80004d80:	6105                	add	sp,sp,32
    80004d82:	8082                	ret
    pi->readopen = 0;
    80004d84:	2204a023          	sw	zero,544(s1)
    wakeup(&pi->nwrite);
    80004d88:	21c48513          	add	a0,s1,540
    80004d8c:	8b9fd0ef          	jal	80002644 <wakeup>
    80004d90:	bfd9                	j	80004d66 <pipeclose+0x24>
    release(&pi->lock);
    80004d92:	8526                	mv	a0,s1
    80004d94:	b78fd0ef          	jal	8000210c <release>
}
    80004d98:	b7c5                	j	80004d78 <pipeclose+0x36>

0000000080004d9a <pipewrite>:

int
pipewrite(struct pipe *pi, uint64 addr, int n)
{
    80004d9a:	711d                	add	sp,sp,-96
    80004d9c:	ec86                	sd	ra,88(sp)
    80004d9e:	e8a2                	sd	s0,80(sp)
    80004da0:	e4a6                	sd	s1,72(sp)
    80004da2:	e0ca                	sd	s2,64(sp)
    80004da4:	fc4e                	sd	s3,56(sp)
    80004da6:	f852                	sd	s4,48(sp)
    80004da8:	f456                	sd	s5,40(sp)
    80004daa:	f05a                	sd	s6,32(sp)
    80004dac:	ec5e                	sd	s7,24(sp)
    80004dae:	e862                	sd	s8,16(sp)
    80004db0:	1080                	add	s0,sp,96
    80004db2:	84aa                	mv	s1,a0
    80004db4:	8aae                	mv	s5,a1
    80004db6:	8a32                	mv	s4,a2
  int i = 0;
  struct proc *pr = myproc();
    80004db8:	faafd0ef          	jal	80002562 <myproc>
    80004dbc:	89aa                	mv	s3,a0

  acquire(&pi->lock);
    80004dbe:	8526                	mv	a0,s1
    80004dc0:	aa6fd0ef          	jal	80002066 <acquire>
  while(i < n){
    80004dc4:	09405c63          	blez	s4,80004e5c <pipewrite+0xc2>
  int i = 0;
    80004dc8:	4901                	li	s2,0
    if(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
      wakeup(&pi->nread);
      sleep(&pi->nwrite, &pi->lock);
    } else {
      char ch;
      if(copyin(pr->pagetable, &ch, addr + i, 1) == -1)
    80004dca:	5b7d                	li	s6,-1
      wakeup(&pi->nread);
    80004dcc:	21848c13          	add	s8,s1,536
      sleep(&pi->nwrite, &pi->lock);
    80004dd0:	21c48b93          	add	s7,s1,540
    80004dd4:	a81d                	j	80004e0a <pipewrite+0x70>
      release(&pi->lock);
    80004dd6:	8526                	mv	a0,s1
    80004dd8:	b34fd0ef          	jal	8000210c <release>
      return -1;
    80004ddc:	597d                	li	s2,-1
  }
  wakeup(&pi->nread);
  release(&pi->lock);

  return i;
}
    80004dde:	854a                	mv	a0,s2
    80004de0:	60e6                	ld	ra,88(sp)
    80004de2:	6446                	ld	s0,80(sp)
    80004de4:	64a6                	ld	s1,72(sp)
    80004de6:	6906                	ld	s2,64(sp)
    80004de8:	79e2                	ld	s3,56(sp)
    80004dea:	7a42                	ld	s4,48(sp)
    80004dec:	7aa2                	ld	s5,40(sp)
    80004dee:	7b02                	ld	s6,32(sp)
    80004df0:	6be2                	ld	s7,24(sp)
    80004df2:	6c42                	ld	s8,16(sp)
    80004df4:	6125                	add	sp,sp,96
    80004df6:	8082                	ret
      wakeup(&pi->nread);
    80004df8:	8562                	mv	a0,s8
    80004dfa:	84bfd0ef          	jal	80002644 <wakeup>
      sleep(&pi->nwrite, &pi->lock);
    80004dfe:	85a6                	mv	a1,s1
    80004e00:	855e                	mv	a0,s7
    80004e02:	991fd0ef          	jal	80002792 <sleep>
  while(i < n){
    80004e06:	05495c63          	bge	s2,s4,80004e5e <pipewrite+0xc4>
    if(pi->readopen == 0 || killed(pr)){
    80004e0a:	2204a783          	lw	a5,544(s1)
    80004e0e:	d7e1                	beqz	a5,80004dd6 <pipewrite+0x3c>
    80004e10:	854e                	mv	a0,s3
    80004e12:	806fe0ef          	jal	80002e18 <killed>
    80004e16:	f161                	bnez	a0,80004dd6 <pipewrite+0x3c>
    if(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
    80004e18:	2184a783          	lw	a5,536(s1)
    80004e1c:	21c4a703          	lw	a4,540(s1)
    80004e20:	2007879b          	addw	a5,a5,512
    80004e24:	fcf70ae3          	beq	a4,a5,80004df8 <pipewrite+0x5e>
      if(copyin(pr->pagetable, &ch, addr + i, 1) == -1)
    80004e28:	4685                	li	a3,1
    80004e2a:	01590633          	add	a2,s2,s5
    80004e2e:	faf40593          	add	a1,s0,-81
    80004e32:	0c89b503          	ld	a0,200(s3)
    80004e36:	debfd0ef          	jal	80002c20 <copyin>
    80004e3a:	03650263          	beq	a0,s6,80004e5e <pipewrite+0xc4>
      pi->data[pi->nwrite++ % PIPESIZE] = ch;
    80004e3e:	21c4a783          	lw	a5,540(s1)
    80004e42:	0017871b          	addw	a4,a5,1
    80004e46:	20e4ae23          	sw	a4,540(s1)
    80004e4a:	1ff7f793          	and	a5,a5,511
    80004e4e:	97a6                	add	a5,a5,s1
    80004e50:	faf44703          	lbu	a4,-81(s0)
    80004e54:	00e78c23          	sb	a4,24(a5)
      i++;
    80004e58:	2905                	addw	s2,s2,1
    80004e5a:	b775                	j	80004e06 <pipewrite+0x6c>
  int i = 0;
    80004e5c:	4901                	li	s2,0
  wakeup(&pi->nread);
    80004e5e:	21848513          	add	a0,s1,536
    80004e62:	fe2fd0ef          	jal	80002644 <wakeup>
  release(&pi->lock);
    80004e66:	8526                	mv	a0,s1
    80004e68:	aa4fd0ef          	jal	8000210c <release>
  return i;
    80004e6c:	bf8d                	j	80004dde <pipewrite+0x44>

0000000080004e6e <piperead>:

int
piperead(struct pipe *pi, uint64 addr, int n)
{
    80004e6e:	715d                	add	sp,sp,-80
    80004e70:	e486                	sd	ra,72(sp)
    80004e72:	e0a2                	sd	s0,64(sp)
    80004e74:	fc26                	sd	s1,56(sp)
    80004e76:	f84a                	sd	s2,48(sp)
    80004e78:	f44e                	sd	s3,40(sp)
    80004e7a:	f052                	sd	s4,32(sp)
    80004e7c:	ec56                	sd	s5,24(sp)
    80004e7e:	e85a                	sd	s6,16(sp)
    80004e80:	0880                	add	s0,sp,80
    80004e82:	84aa                	mv	s1,a0
    80004e84:	892e                	mv	s2,a1
    80004e86:	8ab2                	mv	s5,a2
  int i;
  struct proc *pr = myproc();
    80004e88:	edafd0ef          	jal	80002562 <myproc>
    80004e8c:	8a2a                	mv	s4,a0
  char ch;

  acquire(&pi->lock);
    80004e8e:	8526                	mv	a0,s1
    80004e90:	9d6fd0ef          	jal	80002066 <acquire>
  while(pi->nread == pi->nwrite && pi->writeopen){  //DOC: pipe-empty
    80004e94:	2184a703          	lw	a4,536(s1)
    80004e98:	21c4a783          	lw	a5,540(s1)
    if(killed(pr)){
      release(&pi->lock);
      return -1;
    }
    sleep(&pi->nread, &pi->lock); //DOC: piperead-sleep
    80004e9c:	21848993          	add	s3,s1,536
  while(pi->nread == pi->nwrite && pi->writeopen){  //DOC: pipe-empty
    80004ea0:	02f71363          	bne	a4,a5,80004ec6 <piperead+0x58>
    80004ea4:	2244a783          	lw	a5,548(s1)
    80004ea8:	cf99                	beqz	a5,80004ec6 <piperead+0x58>
    if(killed(pr)){
    80004eaa:	8552                	mv	a0,s4
    80004eac:	f6dfd0ef          	jal	80002e18 <killed>
    80004eb0:	e151                	bnez	a0,80004f34 <piperead+0xc6>
    sleep(&pi->nread, &pi->lock); //DOC: piperead-sleep
    80004eb2:	85a6                	mv	a1,s1
    80004eb4:	854e                	mv	a0,s3
    80004eb6:	8ddfd0ef          	jal	80002792 <sleep>
  while(pi->nread == pi->nwrite && pi->writeopen){  //DOC: pipe-empty
    80004eba:	2184a703          	lw	a4,536(s1)
    80004ebe:	21c4a783          	lw	a5,540(s1)
    80004ec2:	fef701e3          	beq	a4,a5,80004ea4 <piperead+0x36>
  }
  for(i = 0; i < n; i++){  //DOC: piperead-copy
    80004ec6:	4981                	li	s3,0
    if(pi->nread == pi->nwrite)
      break;
    ch = pi->data[pi->nread % PIPESIZE];
    if(copyout(pr->pagetable, addr + i, &ch, 1) == -1) {
    80004ec8:	5b7d                	li	s6,-1
  for(i = 0; i < n; i++){  //DOC: piperead-copy
    80004eca:	05505363          	blez	s5,80004f10 <piperead+0xa2>
    if(pi->nread == pi->nwrite)
    80004ece:	2184a783          	lw	a5,536(s1)
    80004ed2:	21c4a703          	lw	a4,540(s1)
    80004ed6:	02f70d63          	beq	a4,a5,80004f10 <piperead+0xa2>
    ch = pi->data[pi->nread % PIPESIZE];
    80004eda:	1ff7f793          	and	a5,a5,511
    80004ede:	97a6                	add	a5,a5,s1
    80004ee0:	0187c783          	lbu	a5,24(a5)
    80004ee4:	faf40fa3          	sb	a5,-65(s0)
    if(copyout(pr->pagetable, addr + i, &ch, 1) == -1) {
    80004ee8:	4685                	li	a3,1
    80004eea:	fbf40613          	add	a2,s0,-65
    80004eee:	85ca                	mv	a1,s2
    80004ef0:	0c8a3503          	ld	a0,200(s4)
    80004ef4:	ce3fd0ef          	jal	80002bd6 <copyout>
    80004ef8:	05650363          	beq	a0,s6,80004f3e <piperead+0xd0>
      if(i == 0)
        i = -1;
      break;
    }
    pi->nread++;
    80004efc:	2184a783          	lw	a5,536(s1)
    80004f00:	2785                	addw	a5,a5,1
    80004f02:	20f4ac23          	sw	a5,536(s1)
  for(i = 0; i < n; i++){  //DOC: piperead-copy
    80004f06:	2985                	addw	s3,s3,1
    80004f08:	0905                	add	s2,s2,1
    80004f0a:	fd3a92e3          	bne	s5,s3,80004ece <piperead+0x60>
    80004f0e:	89d6                	mv	s3,s5
  }
  wakeup(&pi->nwrite);  //DOC: piperead-wakeup
    80004f10:	21c48513          	add	a0,s1,540
    80004f14:	f30fd0ef          	jal	80002644 <wakeup>
  release(&pi->lock);
    80004f18:	8526                	mv	a0,s1
    80004f1a:	9f2fd0ef          	jal	8000210c <release>
  return i;
}
    80004f1e:	854e                	mv	a0,s3
    80004f20:	60a6                	ld	ra,72(sp)
    80004f22:	6406                	ld	s0,64(sp)
    80004f24:	74e2                	ld	s1,56(sp)
    80004f26:	7942                	ld	s2,48(sp)
    80004f28:	79a2                	ld	s3,40(sp)
    80004f2a:	7a02                	ld	s4,32(sp)
    80004f2c:	6ae2                	ld	s5,24(sp)
    80004f2e:	6b42                	ld	s6,16(sp)
    80004f30:	6161                	add	sp,sp,80
    80004f32:	8082                	ret
      release(&pi->lock);
    80004f34:	8526                	mv	a0,s1
    80004f36:	9d6fd0ef          	jal	8000210c <release>
      return -1;
    80004f3a:	59fd                	li	s3,-1
    80004f3c:	b7cd                	j	80004f1e <piperead+0xb0>
      if(i == 0)
    80004f3e:	fc0999e3          	bnez	s3,80004f10 <piperead+0xa2>
        i = -1;
    80004f42:	89aa                	mv	s3,a0
    80004f44:	b7f1                	j	80004f10 <piperead+0xa2>

0000000080004f46 <write_head>:
// Write in-memory log header to disk.
// This is the true point at which the
// current transaction commits.
static void
write_head(void)
{
    80004f46:	1101                	add	sp,sp,-32
    80004f48:	ec06                	sd	ra,24(sp)
    80004f4a:	e822                	sd	s0,16(sp)
    80004f4c:	e426                	sd	s1,8(sp)
    80004f4e:	e04a                	sd	s2,0(sp)
    80004f50:	1000                	add	s0,sp,32
  struct buf *buf = bread(log.dev, log.start);
    80004f52:	00012917          	auipc	s2,0x12
    80004f56:	65e90913          	add	s2,s2,1630 # 800175b0 <log>
    80004f5a:	01892583          	lw	a1,24(s2)
    80004f5e:	02492503          	lw	a0,36(s2)
    80004f62:	c8efe0ef          	jal	800033f0 <bread>
    80004f66:	84aa                	mv	s1,a0
  struct logheader *hb = (struct logheader *) (buf->data);
  int i;
  hb->n = log.lh.n;
    80004f68:	02892603          	lw	a2,40(s2)
    80004f6c:	cd30                	sw	a2,88(a0)
  for (i = 0; i < log.lh.n; i++) {
    80004f6e:	00c05f63          	blez	a2,80004f8c <write_head+0x46>
    80004f72:	00012717          	auipc	a4,0x12
    80004f76:	66a70713          	add	a4,a4,1642 # 800175dc <log+0x2c>
    80004f7a:	87aa                	mv	a5,a0
    80004f7c:	060a                	sll	a2,a2,0x2
    80004f7e:	962a                	add	a2,a2,a0
    hb->block[i] = log.lh.block[i];
    80004f80:	4314                	lw	a3,0(a4)
    80004f82:	cff4                	sw	a3,92(a5)
  for (i = 0; i < log.lh.n; i++) {
    80004f84:	0711                	add	a4,a4,4
    80004f86:	0791                	add	a5,a5,4
    80004f88:	fec79ce3          	bne	a5,a2,80004f80 <write_head+0x3a>
  }
  bwrite(buf);
    80004f8c:	8526                	mv	a0,s1
    80004f8e:	c8efe0ef          	jal	8000341c <bwrite>
  brelse(buf);
    80004f92:	8526                	mv	a0,s1
    80004f94:	cbcfe0ef          	jal	80003450 <brelse>
}
    80004f98:	60e2                	ld	ra,24(sp)
    80004f9a:	6442                	ld	s0,16(sp)
    80004f9c:	64a2                	ld	s1,8(sp)
    80004f9e:	6902                	ld	s2,0(sp)
    80004fa0:	6105                	add	sp,sp,32
    80004fa2:	8082                	ret

0000000080004fa4 <install_trans>:
  for (tail = 0; tail < log.lh.n; tail++) {
    80004fa4:	00012797          	auipc	a5,0x12
    80004fa8:	6347a783          	lw	a5,1588(a5) # 800175d8 <log+0x28>
    80004fac:	0af05e63          	blez	a5,80005068 <install_trans+0xc4>
{
    80004fb0:	715d                	add	sp,sp,-80
    80004fb2:	e486                	sd	ra,72(sp)
    80004fb4:	e0a2                	sd	s0,64(sp)
    80004fb6:	fc26                	sd	s1,56(sp)
    80004fb8:	f84a                	sd	s2,48(sp)
    80004fba:	f44e                	sd	s3,40(sp)
    80004fbc:	f052                	sd	s4,32(sp)
    80004fbe:	ec56                	sd	s5,24(sp)
    80004fc0:	e85a                	sd	s6,16(sp)
    80004fc2:	e45e                	sd	s7,8(sp)
    80004fc4:	0880                	add	s0,sp,80
    80004fc6:	8b2a                	mv	s6,a0
    80004fc8:	00012a97          	auipc	s5,0x12
    80004fcc:	614a8a93          	add	s5,s5,1556 # 800175dc <log+0x2c>
  for (tail = 0; tail < log.lh.n; tail++) {
    80004fd0:	4981                	li	s3,0
      printf("recovering tail %d dst %d\n", tail, log.lh.block[tail]);
    80004fd2:	00001b97          	auipc	s7,0x1
    80004fd6:	556b8b93          	add	s7,s7,1366 # 80006528 <syscalls+0x578>
    struct buf *lbuf = bread(log.dev, log.start+tail+1); // read log block
    80004fda:	00012a17          	auipc	s4,0x12
    80004fde:	5d6a0a13          	add	s4,s4,1494 # 800175b0 <log>
    80004fe2:	a025                	j	8000500a <install_trans+0x66>
      printf("recovering tail %d dst %d\n", tail, log.lh.block[tail]);
    80004fe4:	000aa603          	lw	a2,0(s5)
    80004fe8:	85ce                	mv	a1,s3
    80004fea:	855e                	mv	a0,s7
    80004fec:	b9afb0ef          	jal	80000386 <printf>
    80004ff0:	a839                	j	8000500e <install_trans+0x6a>
    brelse(lbuf);
    80004ff2:	854a                	mv	a0,s2
    80004ff4:	c5cfe0ef          	jal	80003450 <brelse>
    brelse(dbuf);
    80004ff8:	8526                	mv	a0,s1
    80004ffa:	c56fe0ef          	jal	80003450 <brelse>
  for (tail = 0; tail < log.lh.n; tail++) {
    80004ffe:	2985                	addw	s3,s3,1
    80005000:	0a91                	add	s5,s5,4
    80005002:	028a2783          	lw	a5,40(s4)
    80005006:	04f9d663          	bge	s3,a5,80005052 <install_trans+0xae>
    if(recovering) {
    8000500a:	fc0b1de3          	bnez	s6,80004fe4 <install_trans+0x40>
    struct buf *lbuf = bread(log.dev, log.start+tail+1); // read log block
    8000500e:	018a2583          	lw	a1,24(s4)
    80005012:	013585bb          	addw	a1,a1,s3
    80005016:	2585                	addw	a1,a1,1
    80005018:	024a2503          	lw	a0,36(s4)
    8000501c:	bd4fe0ef          	jal	800033f0 <bread>
    80005020:	892a                	mv	s2,a0
    struct buf *dbuf = bread(log.dev, log.lh.block[tail]); // read dst
    80005022:	000aa583          	lw	a1,0(s5)
    80005026:	024a2503          	lw	a0,36(s4)
    8000502a:	bc6fe0ef          	jal	800033f0 <bread>
    8000502e:	84aa                	mv	s1,a0
    memmove(dbuf->data, lbuf->data, BSIZE);  // copy block to dst
    80005030:	40000613          	li	a2,1024
    80005034:	05890593          	add	a1,s2,88
    80005038:	05850513          	add	a0,a0,88
    8000503c:	35a000ef          	jal	80005396 <memmove>
    bwrite(dbuf);  // write dst to disk
    80005040:	8526                	mv	a0,s1
    80005042:	bdafe0ef          	jal	8000341c <bwrite>
    if(recovering == 0)
    80005046:	fa0b16e3          	bnez	s6,80004ff2 <install_trans+0x4e>
      bunpin(dbuf);
    8000504a:	8526                	mv	a0,s1
    8000504c:	cc2fe0ef          	jal	8000350e <bunpin>
    80005050:	b74d                	j	80004ff2 <install_trans+0x4e>
}
    80005052:	60a6                	ld	ra,72(sp)
    80005054:	6406                	ld	s0,64(sp)
    80005056:	74e2                	ld	s1,56(sp)
    80005058:	7942                	ld	s2,48(sp)
    8000505a:	79a2                	ld	s3,40(sp)
    8000505c:	7a02                	ld	s4,32(sp)
    8000505e:	6ae2                	ld	s5,24(sp)
    80005060:	6b42                	ld	s6,16(sp)
    80005062:	6ba2                	ld	s7,8(sp)
    80005064:	6161                	add	sp,sp,80
    80005066:	8082                	ret
    80005068:	8082                	ret

000000008000506a <initlog>:
{
    8000506a:	7179                	add	sp,sp,-48
    8000506c:	f406                	sd	ra,40(sp)
    8000506e:	f022                	sd	s0,32(sp)
    80005070:	ec26                	sd	s1,24(sp)
    80005072:	e84a                	sd	s2,16(sp)
    80005074:	e44e                	sd	s3,8(sp)
    80005076:	1800                	add	s0,sp,48
    80005078:	892a                	mv	s2,a0
    8000507a:	89ae                	mv	s3,a1
  initlock(&log.lock, "log");
    8000507c:	00012497          	auipc	s1,0x12
    80005080:	53448493          	add	s1,s1,1332 # 800175b0 <log>
    80005084:	00001597          	auipc	a1,0x1
    80005088:	4c458593          	add	a1,a1,1220 # 80006548 <syscalls+0x598>
    8000508c:	8526                	mv	a0,s1
    8000508e:	f77fc0ef          	jal	80002004 <initlock>
  log.start = sb->logstart;
    80005092:	0149a583          	lw	a1,20(s3)
    80005096:	cc8c                	sw	a1,24(s1)
  log.dev = dev;
    80005098:	0324a223          	sw	s2,36(s1)
  struct buf *buf = bread(log.dev, log.start);
    8000509c:	854a                	mv	a0,s2
    8000509e:	b52fe0ef          	jal	800033f0 <bread>
  log.lh.n = lh->n;
    800050a2:	4d30                	lw	a2,88(a0)
    800050a4:	d490                	sw	a2,40(s1)
  for (i = 0; i < log.lh.n; i++) {
    800050a6:	00c05f63          	blez	a2,800050c4 <initlog+0x5a>
    800050aa:	87aa                	mv	a5,a0
    800050ac:	00012717          	auipc	a4,0x12
    800050b0:	53070713          	add	a4,a4,1328 # 800175dc <log+0x2c>
    800050b4:	060a                	sll	a2,a2,0x2
    800050b6:	962a                	add	a2,a2,a0
    log.lh.block[i] = lh->block[i];
    800050b8:	4ff4                	lw	a3,92(a5)
    800050ba:	c314                	sw	a3,0(a4)
  for (i = 0; i < log.lh.n; i++) {
    800050bc:	0791                	add	a5,a5,4
    800050be:	0711                	add	a4,a4,4
    800050c0:	fec79ce3          	bne	a5,a2,800050b8 <initlog+0x4e>
  brelse(buf);
    800050c4:	b8cfe0ef          	jal	80003450 <brelse>

static void
recover_from_log(void)
{
  read_head();
  install_trans(1); // if committed, copy from log to disk
    800050c8:	4505                	li	a0,1
    800050ca:	edbff0ef          	jal	80004fa4 <install_trans>
  log.lh.n = 0;
    800050ce:	00012797          	auipc	a5,0x12
    800050d2:	5007a523          	sw	zero,1290(a5) # 800175d8 <log+0x28>
  write_head(); // clear the log
    800050d6:	e71ff0ef          	jal	80004f46 <write_head>
}
    800050da:	70a2                	ld	ra,40(sp)
    800050dc:	7402                	ld	s0,32(sp)
    800050de:	64e2                	ld	s1,24(sp)
    800050e0:	6942                	ld	s2,16(sp)
    800050e2:	69a2                	ld	s3,8(sp)
    800050e4:	6145                	add	sp,sp,48
    800050e6:	8082                	ret

00000000800050e8 <begin_op>:
}

// called at the start of each FS system call.
void
begin_op(void)
{
    800050e8:	1101                	add	sp,sp,-32
    800050ea:	ec06                	sd	ra,24(sp)
    800050ec:	e822                	sd	s0,16(sp)
    800050ee:	e426                	sd	s1,8(sp)
    800050f0:	e04a                	sd	s2,0(sp)
    800050f2:	1000                	add	s0,sp,32
  acquire(&log.lock);
    800050f4:	00012517          	auipc	a0,0x12
    800050f8:	4bc50513          	add	a0,a0,1212 # 800175b0 <log>
    800050fc:	f6bfc0ef          	jal	80002066 <acquire>
  while(1){
    if(log.committing){
    80005100:	00012497          	auipc	s1,0x12
    80005104:	4b048493          	add	s1,s1,1200 # 800175b0 <log>
      sleep(&log, &log.lock);
    } else if(log.lh.n + (log.outstanding+1)*MAXOPBLOCKS > LOGBLOCKS){
    80005108:	4979                	li	s2,30
    8000510a:	a029                	j	80005114 <begin_op+0x2c>
      sleep(&log, &log.lock);
    8000510c:	85a6                	mv	a1,s1
    8000510e:	8526                	mv	a0,s1
    80005110:	e82fd0ef          	jal	80002792 <sleep>
    if(log.committing){
    80005114:	509c                	lw	a5,32(s1)
    80005116:	fbfd                	bnez	a5,8000510c <begin_op+0x24>
    } else if(log.lh.n + (log.outstanding+1)*MAXOPBLOCKS > LOGBLOCKS){
    80005118:	4cd8                	lw	a4,28(s1)
    8000511a:	2705                	addw	a4,a4,1
    8000511c:	0027179b          	sllw	a5,a4,0x2
    80005120:	9fb9                	addw	a5,a5,a4
    80005122:	0017979b          	sllw	a5,a5,0x1
    80005126:	5494                	lw	a3,40(s1)
    80005128:	9fb5                	addw	a5,a5,a3
    8000512a:	00f95763          	bge	s2,a5,80005138 <begin_op+0x50>
      // this op might exhaust log space; wait for commit.
      sleep(&log, &log.lock);
    8000512e:	85a6                	mv	a1,s1
    80005130:	8526                	mv	a0,s1
    80005132:	e60fd0ef          	jal	80002792 <sleep>
    80005136:	bff9                	j	80005114 <begin_op+0x2c>
    } else {
      log.outstanding += 1;
    80005138:	00012517          	auipc	a0,0x12
    8000513c:	47850513          	add	a0,a0,1144 # 800175b0 <log>
    80005140:	cd58                	sw	a4,28(a0)
      release(&log.lock);
    80005142:	fcbfc0ef          	jal	8000210c <release>
      break;
    }
  }
}
    80005146:	60e2                	ld	ra,24(sp)
    80005148:	6442                	ld	s0,16(sp)
    8000514a:	64a2                	ld	s1,8(sp)
    8000514c:	6902                	ld	s2,0(sp)
    8000514e:	6105                	add	sp,sp,32
    80005150:	8082                	ret

0000000080005152 <end_op>:

// called at the end of each FS system call.
// commits if this was the last outstanding operation.
void
end_op(void)
{
    80005152:	7139                	add	sp,sp,-64
    80005154:	fc06                	sd	ra,56(sp)
    80005156:	f822                	sd	s0,48(sp)
    80005158:	f426                	sd	s1,40(sp)
    8000515a:	f04a                	sd	s2,32(sp)
    8000515c:	ec4e                	sd	s3,24(sp)
    8000515e:	e852                	sd	s4,16(sp)
    80005160:	e456                	sd	s5,8(sp)
    80005162:	0080                	add	s0,sp,64
  int do_commit = 0;

  acquire(&log.lock);
    80005164:	00012497          	auipc	s1,0x12
    80005168:	44c48493          	add	s1,s1,1100 # 800175b0 <log>
    8000516c:	8526                	mv	a0,s1
    8000516e:	ef9fc0ef          	jal	80002066 <acquire>
  log.outstanding -= 1;
    80005172:	4cdc                	lw	a5,28(s1)
    80005174:	37fd                	addw	a5,a5,-1
    80005176:	ccdc                	sw	a5,28(s1)
  if(log.committing)
    80005178:	509c                	lw	a5,32(s1)
    8000517a:	e3b9                	bnez	a5,800051c0 <end_op+0x6e>
    panic("log.committing");
  if(log.outstanding == 0){
    8000517c:	00012917          	auipc	s2,0x12
    80005180:	45092903          	lw	s2,1104(s2) # 800175cc <log+0x1c>
    80005184:	04091563          	bnez	s2,800051ce <end_op+0x7c>
    do_commit = 1;
    log.committing = 1;
    80005188:	00012497          	auipc	s1,0x12
    8000518c:	42848493          	add	s1,s1,1064 # 800175b0 <log>
    80005190:	4785                	li	a5,1
    80005192:	d09c                	sw	a5,32(s1)
    // begin_op() may be waiting for log space,
    // and decrementing log.outstanding has decreased
    // the amount of reserved space.
    wakeup(&log);
  }
  release(&log.lock);
    80005194:	8526                	mv	a0,s1
    80005196:	f77fc0ef          	jal	8000210c <release>
}

static void
commit()
{
  if (log.lh.n > 0) {
    8000519a:	549c                	lw	a5,40(s1)
    8000519c:	04f04c63          	bgtz	a5,800051f4 <end_op+0xa2>
    acquire(&log.lock);
    800051a0:	00012497          	auipc	s1,0x12
    800051a4:	41048493          	add	s1,s1,1040 # 800175b0 <log>
    800051a8:	8526                	mv	a0,s1
    800051aa:	ebdfc0ef          	jal	80002066 <acquire>
    log.committing = 0;
    800051ae:	0204a023          	sw	zero,32(s1)
    wakeup(&log);
    800051b2:	8526                	mv	a0,s1
    800051b4:	c90fd0ef          	jal	80002644 <wakeup>
    release(&log.lock);
    800051b8:	8526                	mv	a0,s1
    800051ba:	f53fc0ef          	jal	8000210c <release>
}
    800051be:	a015                	j	800051e2 <end_op+0x90>
    panic("log.committing");
    800051c0:	00001517          	auipc	a0,0x1
    800051c4:	39050513          	add	a0,a0,912 # 80006550 <syscalls+0x5a0>
    800051c8:	fd8fb0ef          	jal	800009a0 <panic>
    800051cc:	bf45                	j	8000517c <end_op+0x2a>
    wakeup(&log);
    800051ce:	00012497          	auipc	s1,0x12
    800051d2:	3e248493          	add	s1,s1,994 # 800175b0 <log>
    800051d6:	8526                	mv	a0,s1
    800051d8:	c6cfd0ef          	jal	80002644 <wakeup>
  release(&log.lock);
    800051dc:	8526                	mv	a0,s1
    800051de:	f2ffc0ef          	jal	8000210c <release>
}
    800051e2:	70e2                	ld	ra,56(sp)
    800051e4:	7442                	ld	s0,48(sp)
    800051e6:	74a2                	ld	s1,40(sp)
    800051e8:	7902                	ld	s2,32(sp)
    800051ea:	69e2                	ld	s3,24(sp)
    800051ec:	6a42                	ld	s4,16(sp)
    800051ee:	6aa2                	ld	s5,8(sp)
    800051f0:	6121                	add	sp,sp,64
    800051f2:	8082                	ret
  for (tail = 0; tail < log.lh.n; tail++) {
    800051f4:	00012a97          	auipc	s5,0x12
    800051f8:	3e8a8a93          	add	s5,s5,1000 # 800175dc <log+0x2c>
    struct buf *to = bread(log.dev, log.start+tail+1); // log block
    800051fc:	00012a17          	auipc	s4,0x12
    80005200:	3b4a0a13          	add	s4,s4,948 # 800175b0 <log>
    80005204:	018a2583          	lw	a1,24(s4)
    80005208:	012585bb          	addw	a1,a1,s2
    8000520c:	2585                	addw	a1,a1,1
    8000520e:	024a2503          	lw	a0,36(s4)
    80005212:	9defe0ef          	jal	800033f0 <bread>
    80005216:	84aa                	mv	s1,a0
    struct buf *from = bread(log.dev, log.lh.block[tail]); // cache block
    80005218:	000aa583          	lw	a1,0(s5)
    8000521c:	024a2503          	lw	a0,36(s4)
    80005220:	9d0fe0ef          	jal	800033f0 <bread>
    80005224:	89aa                	mv	s3,a0
    memmove(to->data, from->data, BSIZE);
    80005226:	40000613          	li	a2,1024
    8000522a:	05850593          	add	a1,a0,88
    8000522e:	05848513          	add	a0,s1,88
    80005232:	164000ef          	jal	80005396 <memmove>
    bwrite(to);  // write the log
    80005236:	8526                	mv	a0,s1
    80005238:	9e4fe0ef          	jal	8000341c <bwrite>
    brelse(from);
    8000523c:	854e                	mv	a0,s3
    8000523e:	a12fe0ef          	jal	80003450 <brelse>
    brelse(to);
    80005242:	8526                	mv	a0,s1
    80005244:	a0cfe0ef          	jal	80003450 <brelse>
  for (tail = 0; tail < log.lh.n; tail++) {
    80005248:	2905                	addw	s2,s2,1
    8000524a:	0a91                	add	s5,s5,4
    8000524c:	028a2783          	lw	a5,40(s4)
    80005250:	faf94ae3          	blt	s2,a5,80005204 <end_op+0xb2>
    write_log();     // Write modified blocks from cache to log
    write_head();    // Write header to disk -- the real commit
    80005254:	cf3ff0ef          	jal	80004f46 <write_head>
    install_trans(0); // Now install writes to home locations
    80005258:	4501                	li	a0,0
    8000525a:	d4bff0ef          	jal	80004fa4 <install_trans>
    log.lh.n = 0;
    8000525e:	00012797          	auipc	a5,0x12
    80005262:	3607ad23          	sw	zero,890(a5) # 800175d8 <log+0x28>
    write_head();    // Erase the transaction from the log
    80005266:	ce1ff0ef          	jal	80004f46 <write_head>
    8000526a:	bf1d                	j	800051a0 <end_op+0x4e>

000000008000526c <log_write>:
//   modify bp->data[]
//   log_write(bp)
//   brelse(bp)
void
log_write(struct buf *b)
{
    8000526c:	1101                	add	sp,sp,-32
    8000526e:	ec06                	sd	ra,24(sp)
    80005270:	e822                	sd	s0,16(sp)
    80005272:	e426                	sd	s1,8(sp)
    80005274:	e04a                	sd	s2,0(sp)
    80005276:	1000                	add	s0,sp,32
    80005278:	84aa                	mv	s1,a0
  int i;

  acquire(&log.lock);
    8000527a:	00012917          	auipc	s2,0x12
    8000527e:	33690913          	add	s2,s2,822 # 800175b0 <log>
    80005282:	854a                	mv	a0,s2
    80005284:	de3fc0ef          	jal	80002066 <acquire>
  if (log.lh.n >= LOGBLOCKS)
    80005288:	02892703          	lw	a4,40(s2)
    8000528c:	47f5                	li	a5,29
    8000528e:	04e7cf63          	blt	a5,a4,800052ec <log_write+0x80>
    panic("too big a transaction");
  if (log.outstanding < 1)
    80005292:	00012797          	auipc	a5,0x12
    80005296:	33a7a783          	lw	a5,826(a5) # 800175cc <log+0x1c>
    8000529a:	06f05063          	blez	a5,800052fa <log_write+0x8e>
    panic("log_write outside of trans");

  for (i = 0; i < log.lh.n; i++) {
    8000529e:	00012617          	auipc	a2,0x12
    800052a2:	33a62603          	lw	a2,826(a2) # 800175d8 <log+0x28>
    800052a6:	06c05163          	blez	a2,80005308 <log_write+0x9c>
    if (log.lh.block[i] == b->blockno)   // log absorption
    800052aa:	44cc                	lw	a1,12(s1)
    800052ac:	00012717          	auipc	a4,0x12
    800052b0:	33070713          	add	a4,a4,816 # 800175dc <log+0x2c>
  for (i = 0; i < log.lh.n; i++) {
    800052b4:	4781                	li	a5,0
    if (log.lh.block[i] == b->blockno)   // log absorption
    800052b6:	4314                	lw	a3,0(a4)
    800052b8:	04b68963          	beq	a3,a1,8000530a <log_write+0x9e>
  for (i = 0; i < log.lh.n; i++) {
    800052bc:	2785                	addw	a5,a5,1
    800052be:	0711                	add	a4,a4,4
    800052c0:	fec79be3          	bne	a5,a2,800052b6 <log_write+0x4a>
      break;
  }
  log.lh.block[i] = b->blockno;
    800052c4:	0621                	add	a2,a2,8
    800052c6:	060a                	sll	a2,a2,0x2
    800052c8:	00012797          	auipc	a5,0x12
    800052cc:	2e878793          	add	a5,a5,744 # 800175b0 <log>
    800052d0:	97b2                	add	a5,a5,a2
    800052d2:	44d8                	lw	a4,12(s1)
    800052d4:	c7d8                	sw	a4,12(a5)
  if (i == log.lh.n) {  // Add new block to log?
    bpin(b);
    800052d6:	8526                	mv	a0,s1
    800052d8:	a02fe0ef          	jal	800034da <bpin>
    log.lh.n++;
    800052dc:	00012717          	auipc	a4,0x12
    800052e0:	2d470713          	add	a4,a4,724 # 800175b0 <log>
    800052e4:	571c                	lw	a5,40(a4)
    800052e6:	2785                	addw	a5,a5,1
    800052e8:	d71c                	sw	a5,40(a4)
    800052ea:	a825                	j	80005322 <log_write+0xb6>
    panic("too big a transaction");
    800052ec:	00001517          	auipc	a0,0x1
    800052f0:	27450513          	add	a0,a0,628 # 80006560 <syscalls+0x5b0>
    800052f4:	eacfb0ef          	jal	800009a0 <panic>
    800052f8:	bf69                	j	80005292 <log_write+0x26>
    panic("log_write outside of trans");
    800052fa:	00001517          	auipc	a0,0x1
    800052fe:	27e50513          	add	a0,a0,638 # 80006578 <syscalls+0x5c8>
    80005302:	e9efb0ef          	jal	800009a0 <panic>
    80005306:	bf61                	j	8000529e <log_write+0x32>
  for (i = 0; i < log.lh.n; i++) {
    80005308:	4781                	li	a5,0
  log.lh.block[i] = b->blockno;
    8000530a:	00878693          	add	a3,a5,8
    8000530e:	068a                	sll	a3,a3,0x2
    80005310:	00012717          	auipc	a4,0x12
    80005314:	2a070713          	add	a4,a4,672 # 800175b0 <log>
    80005318:	9736                	add	a4,a4,a3
    8000531a:	44d4                	lw	a3,12(s1)
    8000531c:	c754                	sw	a3,12(a4)
  if (i == log.lh.n) {  // Add new block to log?
    8000531e:	faf60ce3          	beq	a2,a5,800052d6 <log_write+0x6a>
  }
  release(&log.lock);
    80005322:	00012517          	auipc	a0,0x12
    80005326:	28e50513          	add	a0,a0,654 # 800175b0 <log>
    8000532a:	de3fc0ef          	jal	8000210c <release>
}
    8000532e:	60e2                	ld	ra,24(sp)
    80005330:	6442                	ld	s0,16(sp)
    80005332:	64a2                	ld	s1,8(sp)
    80005334:	6902                	ld	s2,0(sp)
    80005336:	6105                	add	sp,sp,32
    80005338:	8082                	ret

000000008000533a <memset>:
#include "string.h"

void*
memset(void *dst, int c, uint32 n)
{
    8000533a:	1141                	add	sp,sp,-16
    8000533c:	e422                	sd	s0,8(sp)
    8000533e:	0800                	add	s0,sp,16
  char *cdst = (char *) dst;
  int i;
  for(i = 0; i < n; i++){
    80005340:	ca19                	beqz	a2,80005356 <memset+0x1c>
    80005342:	87aa                	mv	a5,a0
    80005344:	1602                	sll	a2,a2,0x20
    80005346:	9201                	srl	a2,a2,0x20
    80005348:	00a60733          	add	a4,a2,a0
    cdst[i] = c;
    8000534c:	00b78023          	sb	a1,0(a5)
  for(i = 0; i < n; i++){
    80005350:	0785                	add	a5,a5,1
    80005352:	fee79de3          	bne	a5,a4,8000534c <memset+0x12>
  }
  return dst;
}
    80005356:	6422                	ld	s0,8(sp)
    80005358:	0141                	add	sp,sp,16
    8000535a:	8082                	ret

000000008000535c <memcmp>:

int
memcmp(const void *v1, const void *v2, uint32 n)
{
    8000535c:	1141                	add	sp,sp,-16
    8000535e:	e422                	sd	s0,8(sp)
    80005360:	0800                	add	s0,sp,16
  const uint8 *s1, *s2;

  s1 = v1;
  s2 = v2;
  while(n-- > 0){
    80005362:	ca05                	beqz	a2,80005392 <memcmp+0x36>
    80005364:	fff6069b          	addw	a3,a2,-1
    80005368:	1682                	sll	a3,a3,0x20
    8000536a:	9281                	srl	a3,a3,0x20
    8000536c:	0685                	add	a3,a3,1
    8000536e:	96aa                	add	a3,a3,a0
    if(*s1 != *s2)
    80005370:	00054783          	lbu	a5,0(a0)
    80005374:	0005c703          	lbu	a4,0(a1)
    80005378:	00e79863          	bne	a5,a4,80005388 <memcmp+0x2c>
      return *s1 - *s2;
    s1++, s2++;
    8000537c:	0505                	add	a0,a0,1
    8000537e:	0585                	add	a1,a1,1
  while(n-- > 0){
    80005380:	fed518e3          	bne	a0,a3,80005370 <memcmp+0x14>
  }

  return 0;
    80005384:	4501                	li	a0,0
    80005386:	a019                	j	8000538c <memcmp+0x30>
      return *s1 - *s2;
    80005388:	40e7853b          	subw	a0,a5,a4
}
    8000538c:	6422                	ld	s0,8(sp)
    8000538e:	0141                	add	sp,sp,16
    80005390:	8082                	ret
  return 0;
    80005392:	4501                	li	a0,0
    80005394:	bfe5                	j	8000538c <memcmp+0x30>

0000000080005396 <memmove>:

void*
memmove(void *dst, const void *src, uint32 n)
{
    80005396:	1141                	add	sp,sp,-16
    80005398:	e422                	sd	s0,8(sp)
    8000539a:	0800                	add	s0,sp,16
  const char *s;
  char *d;

  if(n == 0)
    8000539c:	c205                	beqz	a2,800053bc <memmove+0x26>
    return dst;
  
  s = src;
  d = dst;
  if(s < d && s + n > d){
    8000539e:	02a5e263          	bltu	a1,a0,800053c2 <memmove+0x2c>
    s += n;
    d += n;
    while(n-- > 0)
      *--d = *--s;
  } else
    while(n-- > 0)
    800053a2:	1602                	sll	a2,a2,0x20
    800053a4:	9201                	srl	a2,a2,0x20
    800053a6:	00c587b3          	add	a5,a1,a2
{
    800053aa:	872a                	mv	a4,a0
      *d++ = *s++;
    800053ac:	0585                	add	a1,a1,1
    800053ae:	0705                	add	a4,a4,1
    800053b0:	fff5c683          	lbu	a3,-1(a1)
    800053b4:	fed70fa3          	sb	a3,-1(a4)
    while(n-- > 0)
    800053b8:	fef59ae3          	bne	a1,a5,800053ac <memmove+0x16>

  return dst;
}
    800053bc:	6422                	ld	s0,8(sp)
    800053be:	0141                	add	sp,sp,16
    800053c0:	8082                	ret
  if(s < d && s + n > d){
    800053c2:	02061693          	sll	a3,a2,0x20
    800053c6:	9281                	srl	a3,a3,0x20
    800053c8:	00d58733          	add	a4,a1,a3
    800053cc:	fce57be3          	bgeu	a0,a4,800053a2 <memmove+0xc>
    d += n;
    800053d0:	96aa                	add	a3,a3,a0
    while(n-- > 0)
    800053d2:	fff6079b          	addw	a5,a2,-1
    800053d6:	1782                	sll	a5,a5,0x20
    800053d8:	9381                	srl	a5,a5,0x20
    800053da:	fff7c793          	not	a5,a5
    800053de:	97ba                	add	a5,a5,a4
      *--d = *--s;
    800053e0:	177d                	add	a4,a4,-1
    800053e2:	16fd                	add	a3,a3,-1
    800053e4:	00074603          	lbu	a2,0(a4)
    800053e8:	00c68023          	sb	a2,0(a3)
    while(n-- > 0)
    800053ec:	fee79ae3          	bne	a5,a4,800053e0 <memmove+0x4a>
    800053f0:	b7f1                	j	800053bc <memmove+0x26>

00000000800053f2 <memcpy>:

// memcpy exists to placate GCC.  Use memmove.
void*
memcpy(void *dst, const void *src, uint32 n)
{
    800053f2:	1141                	add	sp,sp,-16
    800053f4:	e406                	sd	ra,8(sp)
    800053f6:	e022                	sd	s0,0(sp)
    800053f8:	0800                	add	s0,sp,16
  return memmove(dst, src, n);
    800053fa:	f9dff0ef          	jal	80005396 <memmove>
}
    800053fe:	60a2                	ld	ra,8(sp)
    80005400:	6402                	ld	s0,0(sp)
    80005402:	0141                	add	sp,sp,16
    80005404:	8082                	ret

0000000080005406 <strncmp>:

int
strncmp(const char *p, const char *q, uint32 n)
{
    80005406:	1141                	add	sp,sp,-16
    80005408:	e422                	sd	s0,8(sp)
    8000540a:	0800                	add	s0,sp,16
  while(n > 0 && *p && *p == *q)
    8000540c:	ce11                	beqz	a2,80005428 <strncmp+0x22>
    8000540e:	00054783          	lbu	a5,0(a0)
    80005412:	cf89                	beqz	a5,8000542c <strncmp+0x26>
    80005414:	0005c703          	lbu	a4,0(a1)
    80005418:	00f71a63          	bne	a4,a5,8000542c <strncmp+0x26>
    n--, p++, q++;
    8000541c:	367d                	addw	a2,a2,-1
    8000541e:	0505                	add	a0,a0,1
    80005420:	0585                	add	a1,a1,1
  while(n > 0 && *p && *p == *q)
    80005422:	f675                	bnez	a2,8000540e <strncmp+0x8>
  if(n == 0)
    return 0;
    80005424:	4501                	li	a0,0
    80005426:	a809                	j	80005438 <strncmp+0x32>
    80005428:	4501                	li	a0,0
    8000542a:	a039                	j	80005438 <strncmp+0x32>
  if(n == 0)
    8000542c:	ca09                	beqz	a2,8000543e <strncmp+0x38>
  return (uint8)*p - (uint8)*q;
    8000542e:	00054503          	lbu	a0,0(a0)
    80005432:	0005c783          	lbu	a5,0(a1)
    80005436:	9d1d                	subw	a0,a0,a5
}
    80005438:	6422                	ld	s0,8(sp)
    8000543a:	0141                	add	sp,sp,16
    8000543c:	8082                	ret
    return 0;
    8000543e:	4501                	li	a0,0
    80005440:	bfe5                	j	80005438 <strncmp+0x32>

0000000080005442 <strncpy>:

char*
strncpy(char *s, const char *t, int n)
{
    80005442:	1141                	add	sp,sp,-16
    80005444:	e422                	sd	s0,8(sp)
    80005446:	0800                	add	s0,sp,16
  char *os;

  os = s;
  while(n-- > 0 && (*s++ = *t++) != 0)
    80005448:	87aa                	mv	a5,a0
    8000544a:	86b2                	mv	a3,a2
    8000544c:	367d                	addw	a2,a2,-1
    8000544e:	00d05963          	blez	a3,80005460 <strncpy+0x1e>
    80005452:	0785                	add	a5,a5,1
    80005454:	0005c703          	lbu	a4,0(a1)
    80005458:	fee78fa3          	sb	a4,-1(a5)
    8000545c:	0585                	add	a1,a1,1
    8000545e:	f775                	bnez	a4,8000544a <strncpy+0x8>
    ;
  while(n-- > 0)
    80005460:	873e                	mv	a4,a5
    80005462:	9fb5                	addw	a5,a5,a3
    80005464:	37fd                	addw	a5,a5,-1
    80005466:	00c05963          	blez	a2,80005478 <strncpy+0x36>
    *s++ = 0;
    8000546a:	0705                	add	a4,a4,1
    8000546c:	fe070fa3          	sb	zero,-1(a4)
  while(n-- > 0)
    80005470:	40e786bb          	subw	a3,a5,a4
    80005474:	fed04be3          	bgtz	a3,8000546a <strncpy+0x28>
  return os;
}
    80005478:	6422                	ld	s0,8(sp)
    8000547a:	0141                	add	sp,sp,16
    8000547c:	8082                	ret

000000008000547e <safestrcpy>:

// Like strncpy but guaranteed to NUL-terminate.
char*
safestrcpy(char *s, const char *t, int n)
{
    8000547e:	1141                	add	sp,sp,-16
    80005480:	e422                	sd	s0,8(sp)
    80005482:	0800                	add	s0,sp,16
  char *os;

  os = s;
  if(n <= 0)
    80005484:	02c05363          	blez	a2,800054aa <safestrcpy+0x2c>
    80005488:	fff6069b          	addw	a3,a2,-1
    8000548c:	1682                	sll	a3,a3,0x20
    8000548e:	9281                	srl	a3,a3,0x20
    80005490:	96ae                	add	a3,a3,a1
    80005492:	87aa                	mv	a5,a0
    return os;
  while(--n > 0 && (*s++ = *t++) != 0)
    80005494:	00d58963          	beq	a1,a3,800054a6 <safestrcpy+0x28>
    80005498:	0585                	add	a1,a1,1
    8000549a:	0785                	add	a5,a5,1
    8000549c:	fff5c703          	lbu	a4,-1(a1)
    800054a0:	fee78fa3          	sb	a4,-1(a5)
    800054a4:	fb65                	bnez	a4,80005494 <safestrcpy+0x16>
    ;
  *s = 0;
    800054a6:	00078023          	sb	zero,0(a5)
  return os;
}
    800054aa:	6422                	ld	s0,8(sp)
    800054ac:	0141                	add	sp,sp,16
    800054ae:	8082                	ret

00000000800054b0 <strlen>:

int
strlen(const char *s)
{
    800054b0:	1141                	add	sp,sp,-16
    800054b2:	e422                	sd	s0,8(sp)
    800054b4:	0800                	add	s0,sp,16
  int n;

  for(n = 0; s[n]; n++)
    800054b6:	00054783          	lbu	a5,0(a0)
    800054ba:	cf91                	beqz	a5,800054d6 <strlen+0x26>
    800054bc:	0505                	add	a0,a0,1
    800054be:	87aa                	mv	a5,a0
    800054c0:	86be                	mv	a3,a5
    800054c2:	0785                	add	a5,a5,1
    800054c4:	fff7c703          	lbu	a4,-1(a5)
    800054c8:	ff65                	bnez	a4,800054c0 <strlen+0x10>
    800054ca:	40a6853b          	subw	a0,a3,a0
    800054ce:	2505                	addw	a0,a0,1
    ;
  return n;
}
    800054d0:	6422                	ld	s0,8(sp)
    800054d2:	0141                	add	sp,sp,16
    800054d4:	8082                	ret
  for(n = 0; s[n]; n++)
    800054d6:	4501                	li	a0,0
    800054d8:	bfe5                	j	800054d0 <strlen+0x20>

00000000800054da <kfree>:
// which normally should have been returned by a
// call to kalloc().  (The exception is when
// initializing the allocator; see kinit above.)
void
kfree(void *pa)
{
    800054da:	1101                	add	sp,sp,-32
    800054dc:	ec06                	sd	ra,24(sp)
    800054de:	e822                	sd	s0,16(sp)
    800054e0:	e426                	sd	s1,8(sp)
    800054e2:	e04a                	sd	s2,0(sp)
    800054e4:	1000                	add	s0,sp,32
    800054e6:	84aa                	mv	s1,a0
  struct run *r;

  if(((uint64)pa % PGSIZE) != 0 || (char*)pa < end || (uint64)pa >= PHYSTOP)
    800054e8:	03451793          	sll	a5,a0,0x34
    800054ec:	eb99                	bnez	a5,80005502 <kfree+0x28>
    800054ee:	00014797          	auipc	a5,0x14
    800054f2:	b2278793          	add	a5,a5,-1246 # 80019010 <end>
    800054f6:	00f56663          	bltu	a0,a5,80005502 <kfree+0x28>
    800054fa:	47c5                	li	a5,17
    800054fc:	07ee                	sll	a5,a5,0x1b
    800054fe:	00f56863          	bltu	a0,a5,8000550e <kfree+0x34>
    panic("kfree");
    80005502:	00001517          	auipc	a0,0x1
    80005506:	09650513          	add	a0,a0,150 # 80006598 <syscalls+0x5e8>
    8000550a:	c96fb0ef          	jal	800009a0 <panic>

  // Fill with junk to catch dangling refs.
  memset(pa, 1, PGSIZE);
    8000550e:	6605                	lui	a2,0x1
    80005510:	4585                	li	a1,1
    80005512:	8526                	mv	a0,s1
    80005514:	e27ff0ef          	jal	8000533a <memset>

  r = (struct run*)pa;

  acquire(&kmem.lock);
    80005518:	00012917          	auipc	s2,0x12
    8000551c:	14090913          	add	s2,s2,320 # 80017658 <kmem>
    80005520:	854a                	mv	a0,s2
    80005522:	b45fc0ef          	jal	80002066 <acquire>
  r->next = kmem.freelist;
    80005526:	01893783          	ld	a5,24(s2)
    8000552a:	e09c                	sd	a5,0(s1)
  kmem.freelist = r;
    8000552c:	00993c23          	sd	s1,24(s2)
  release(&kmem.lock);
    80005530:	854a                	mv	a0,s2
    80005532:	bdbfc0ef          	jal	8000210c <release>
}
    80005536:	60e2                	ld	ra,24(sp)
    80005538:	6442                	ld	s0,16(sp)
    8000553a:	64a2                	ld	s1,8(sp)
    8000553c:	6902                	ld	s2,0(sp)
    8000553e:	6105                	add	sp,sp,32
    80005540:	8082                	ret

0000000080005542 <freerange>:
{
    80005542:	7179                	add	sp,sp,-48
    80005544:	f406                	sd	ra,40(sp)
    80005546:	f022                	sd	s0,32(sp)
    80005548:	ec26                	sd	s1,24(sp)
    8000554a:	e84a                	sd	s2,16(sp)
    8000554c:	e44e                	sd	s3,8(sp)
    8000554e:	e052                	sd	s4,0(sp)
    80005550:	1800                	add	s0,sp,48
  p = (char*)PGROUNDUP((uint64)pa_start);
    80005552:	6785                	lui	a5,0x1
    80005554:	fff78713          	add	a4,a5,-1 # fff <_entry-0x7ffff001>
    80005558:	00e504b3          	add	s1,a0,a4
    8000555c:	777d                	lui	a4,0xfffff
    8000555e:	8cf9                	and	s1,s1,a4
  for(; p + PGSIZE <= (char*)pa_end; p += PGSIZE)
    80005560:	94be                	add	s1,s1,a5
    80005562:	0095ec63          	bltu	a1,s1,8000557a <freerange+0x38>
    80005566:	892e                	mv	s2,a1
    kfree(p);
    80005568:	7a7d                	lui	s4,0xfffff
  for(; p + PGSIZE <= (char*)pa_end; p += PGSIZE)
    8000556a:	6985                	lui	s3,0x1
    kfree(p);
    8000556c:	01448533          	add	a0,s1,s4
    80005570:	f6bff0ef          	jal	800054da <kfree>
  for(; p + PGSIZE <= (char*)pa_end; p += PGSIZE)
    80005574:	94ce                	add	s1,s1,s3
    80005576:	fe997be3          	bgeu	s2,s1,8000556c <freerange+0x2a>
}
    8000557a:	70a2                	ld	ra,40(sp)
    8000557c:	7402                	ld	s0,32(sp)
    8000557e:	64e2                	ld	s1,24(sp)
    80005580:	6942                	ld	s2,16(sp)
    80005582:	69a2                	ld	s3,8(sp)
    80005584:	6a02                	ld	s4,0(sp)
    80005586:	6145                	add	sp,sp,48
    80005588:	8082                	ret

000000008000558a <kinit>:
{
    8000558a:	1141                	add	sp,sp,-16
    8000558c:	e406                	sd	ra,8(sp)
    8000558e:	e022                	sd	s0,0(sp)
    80005590:	0800                	add	s0,sp,16
  initlock(&kmem.lock, "kmem");
    80005592:	00001597          	auipc	a1,0x1
    80005596:	00e58593          	add	a1,a1,14 # 800065a0 <syscalls+0x5f0>
    8000559a:	00012517          	auipc	a0,0x12
    8000559e:	0be50513          	add	a0,a0,190 # 80017658 <kmem>
    800055a2:	a63fc0ef          	jal	80002004 <initlock>
  freerange(end, (void*)PHYSTOP);
    800055a6:	45c5                	li	a1,17
    800055a8:	05ee                	sll	a1,a1,0x1b
    800055aa:	00014517          	auipc	a0,0x14
    800055ae:	a6650513          	add	a0,a0,-1434 # 80019010 <end>
    800055b2:	f91ff0ef          	jal	80005542 <freerange>
}
    800055b6:	60a2                	ld	ra,8(sp)
    800055b8:	6402                	ld	s0,0(sp)
    800055ba:	0141                	add	sp,sp,16
    800055bc:	8082                	ret

00000000800055be <kalloc>:
// Allocate one 4096-byte page of physical memory.
// Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated.
void *
kalloc(void)
{
    800055be:	1101                	add	sp,sp,-32
    800055c0:	ec06                	sd	ra,24(sp)
    800055c2:	e822                	sd	s0,16(sp)
    800055c4:	e426                	sd	s1,8(sp)
    800055c6:	1000                	add	s0,sp,32
  struct run *r;

  acquire(&kmem.lock);
    800055c8:	00012497          	auipc	s1,0x12
    800055cc:	09048493          	add	s1,s1,144 # 80017658 <kmem>
    800055d0:	8526                	mv	a0,s1
    800055d2:	a95fc0ef          	jal	80002066 <acquire>
  r = kmem.freelist;
    800055d6:	6c84                	ld	s1,24(s1)
  if(r)
    800055d8:	c485                	beqz	s1,80005600 <kalloc+0x42>
    kmem.freelist = r->next;
    800055da:	609c                	ld	a5,0(s1)
    800055dc:	00012517          	auipc	a0,0x12
    800055e0:	07c50513          	add	a0,a0,124 # 80017658 <kmem>
    800055e4:	ed1c                	sd	a5,24(a0)
  release(&kmem.lock);
    800055e6:	b27fc0ef          	jal	8000210c <release>

  if(r)
    memset((char*)r, 5, PGSIZE); // fill with junk
    800055ea:	6605                	lui	a2,0x1
    800055ec:	4595                	li	a1,5
    800055ee:	8526                	mv	a0,s1
    800055f0:	d4bff0ef          	jal	8000533a <memset>
  return (void*)r;
}
    800055f4:	8526                	mv	a0,s1
    800055f6:	60e2                	ld	ra,24(sp)
    800055f8:	6442                	ld	s0,16(sp)
    800055fa:	64a2                	ld	s1,8(sp)
    800055fc:	6105                	add	sp,sp,32
    800055fe:	8082                	ret
  release(&kmem.lock);
    80005600:	00012517          	auipc	a0,0x12
    80005604:	05850513          	add	a0,a0,88 # 80017658 <kmem>
    80005608:	b05fc0ef          	jal	8000210c <release>
  if(r)
    8000560c:	b7e5                	j	800055f4 <kalloc+0x36>

Disassembly of section .trampsec:

0000000080018000 <trampoline>:
        # user page table.
        #

        # save user a0 in sscratch so
        # a0 can be used to get at TRAPFRAME.
        csrw sscratch, a0
    80018000:	14051073          	csrw	sscratch,a0

        # each process has a separate p->trapframe memory area,
        # but it's mapped to the same virtual address
        # (TRAPFRAME) in every process's user page table.
        li a0, TRAPFRAME
    80018004:	02000537          	lui	a0,0x2000
    80018008:	357d                	addw	a0,a0,-1 # 1ffffff <_entry-0x7e000001>
    8001800a:	0536                	sll	a0,a0,0xd
        
        # save the user registers in TRAPFRAME
        sd ra, 40(a0)
    8001800c:	02153423          	sd	ra,40(a0)
        sd sp, 48(a0)
    80018010:	02253823          	sd	sp,48(a0)
        sd gp, 56(a0)
    80018014:	02353c23          	sd	gp,56(a0)
        sd tp, 64(a0)
    80018018:	04453023          	sd	tp,64(a0)
        sd t0, 72(a0)
    8001801c:	04553423          	sd	t0,72(a0)
        sd t1, 80(a0)
    80018020:	04653823          	sd	t1,80(a0)
        sd t2, 88(a0)
    80018024:	04753c23          	sd	t2,88(a0)
        sd s0, 96(a0)
    80018028:	f120                	sd	s0,96(a0)
        sd s1, 104(a0)
    8001802a:	f524                	sd	s1,104(a0)
        sd a1, 120(a0)
    8001802c:	fd2c                	sd	a1,120(a0)
        sd a2, 128(a0)
    8001802e:	e150                	sd	a2,128(a0)
        sd a3, 136(a0)
    80018030:	e554                	sd	a3,136(a0)
        sd a4, 144(a0)
    80018032:	e958                	sd	a4,144(a0)
        sd a5, 152(a0)
    80018034:	ed5c                	sd	a5,152(a0)
        sd a6, 160(a0)
    80018036:	0b053023          	sd	a6,160(a0)
        sd a7, 168(a0)
    8001803a:	0b153423          	sd	a7,168(a0)
        sd s2, 176(a0)
    8001803e:	0b253823          	sd	s2,176(a0)
        sd s3, 184(a0)
    80018042:	0b353c23          	sd	s3,184(a0)
        sd s4, 192(a0)
    80018046:	0d453023          	sd	s4,192(a0)
        sd s5, 200(a0)
    8001804a:	0d553423          	sd	s5,200(a0)
        sd s6, 208(a0)
    8001804e:	0d653823          	sd	s6,208(a0)
        sd s7, 216(a0)
    80018052:	0d753c23          	sd	s7,216(a0)
        sd s8, 224(a0)
    80018056:	0f853023          	sd	s8,224(a0)
        sd s9, 232(a0)
    8001805a:	0f953423          	sd	s9,232(a0)
        sd s10, 240(a0)
    8001805e:	0fa53823          	sd	s10,240(a0)
        sd s11, 248(a0)
    80018062:	0fb53c23          	sd	s11,248(a0)
        sd t3, 256(a0)
    80018066:	11c53023          	sd	t3,256(a0)
        sd t4, 264(a0)
    8001806a:	11d53423          	sd	t4,264(a0)
        sd t5, 272(a0)
    8001806e:	11e53823          	sd	t5,272(a0)
        sd t6, 280(a0)
    80018072:	11f53c23          	sd	t6,280(a0)

	# save the user a0 in p->trapframe->a0
        csrr t0, sscratch
    80018076:	140022f3          	csrr	t0,sscratch
        sd t0, 112(a0)
    8001807a:	06553823          	sd	t0,112(a0)

        # initialize kernel stack pointer, from p->trapframe->kernel_sp
        ld sp, 8(a0)
    8001807e:	00853103          	ld	sp,8(a0)

        # make tp hold the current hartid, from p->trapframe->kernel_hartid
        ld tp, 32(a0)
    80018082:	02053203          	ld	tp,32(a0)

        # load the address of usertrap(), from p->trapframe->kernel_trap
        ld t0, 16(a0)
    80018086:	01053283          	ld	t0,16(a0)

        # fetch the kernel page table address, from p->trapframe->kernel_satp.
        ld t1, 0(a0)
    8001808a:	00053303          	ld	t1,0(a0)

        # wait for any previous memory operations to complete, so that
        # they use the user page table.
        sfence.vma zero, zero
    8001808e:	12000073          	sfence.vma

        # install the kernel page table.
        csrw satp, t1
    80018092:	18031073          	csrw	satp,t1

        # flush now-stale user entries from the TLB.
        sfence.vma zero, zero
    80018096:	12000073          	sfence.vma
                 
        
        # call usertrap()
        jalr t0
    8001809a:	9282                	jalr	t0

000000008001809c <userret>:
userret:
        # usertrap() returns here, with user satp in a0.
        # return from kernel to user.

        # switch to the user page table.
        sfence.vma zero, zero
    8001809c:	12000073          	sfence.vma
        csrw satp, a0
    800180a0:	18051073          	csrw	satp,a0
        sfence.vma zero, zero
    800180a4:	12000073          	sfence.vma

        li a0, TRAPFRAME
    800180a8:	02000537          	lui	a0,0x2000
    800180ac:	357d                	addw	a0,a0,-1 # 1ffffff <_entry-0x7e000001>
    800180ae:	0536                	sll	a0,a0,0xd

        # restore all but a0 from TRAPFRAME
        ld ra, 40(a0)
    800180b0:	02853083          	ld	ra,40(a0)
        ld sp, 48(a0)
    800180b4:	03053103          	ld	sp,48(a0)
        ld gp, 56(a0)
    800180b8:	03853183          	ld	gp,56(a0)
        ld tp, 64(a0)
    800180bc:	04053203          	ld	tp,64(a0)
        ld t0, 72(a0)
    800180c0:	04853283          	ld	t0,72(a0)
        ld t1, 80(a0)
    800180c4:	05053303          	ld	t1,80(a0)
        ld t2, 88(a0)
    800180c8:	05853383          	ld	t2,88(a0)
        ld s0, 96(a0)
    800180cc:	7120                	ld	s0,96(a0)
        ld s1, 104(a0)
    800180ce:	7524                	ld	s1,104(a0)
        ld a1, 120(a0)
    800180d0:	7d2c                	ld	a1,120(a0)
        ld a2, 128(a0)
    800180d2:	6150                	ld	a2,128(a0)
        ld a3, 136(a0)
    800180d4:	6554                	ld	a3,136(a0)
        ld a4, 144(a0)
    800180d6:	6958                	ld	a4,144(a0)
        ld a5, 152(a0)
    800180d8:	6d5c                	ld	a5,152(a0)
        ld a6, 160(a0)
    800180da:	0a053803          	ld	a6,160(a0)
        ld a7, 168(a0)
    800180de:	0a853883          	ld	a7,168(a0)
        ld s2, 176(a0)
    800180e2:	0b053903          	ld	s2,176(a0)
        ld s3, 184(a0)
    800180e6:	0b853983          	ld	s3,184(a0)
        ld s4, 192(a0)
    800180ea:	0c053a03          	ld	s4,192(a0)
        ld s5, 200(a0)
    800180ee:	0c853a83          	ld	s5,200(a0)
        ld s6, 208(a0)
    800180f2:	0d053b03          	ld	s6,208(a0)
        ld s7, 216(a0)
    800180f6:	0d853b83          	ld	s7,216(a0)
        ld s8, 224(a0)
    800180fa:	0e053c03          	ld	s8,224(a0)
        ld s9, 232(a0)
    800180fe:	0e853c83          	ld	s9,232(a0)
        ld s10, 240(a0)
    80018102:	0f053d03          	ld	s10,240(a0)
        ld s11, 248(a0)
    80018106:	0f853d83          	ld	s11,248(a0)
        ld t3, 256(a0)
    8001810a:	10053e03          	ld	t3,256(a0)
        ld t4, 264(a0)
    8001810e:	10853e83          	ld	t4,264(a0)
        ld t5, 272(a0)
    80018112:	11053f03          	ld	t5,272(a0)
        ld t6, 280(a0)
    80018116:	11853f83          	ld	t6,280(a0)

	# restore user a0
        ld a0, 112(a0)
    8001811a:	7928                	ld	a0,112(a0)
        
        # return to user mode and user pc.
        # usertrapret() set up sstatus and sepc.
        sret
    8001811c:	10200073          	sret
	...
